In most cases, developers don’t get to choose a user’s browser. To determine whether a particular user can work with your CSS3 application, then, you need first to detect the user’s browser — and then determine whether that browser is acceptable.
, and tags.
Creating the code required to perform this task by hand isn’t impossible, but it can be hard. Articles like the one at Javascripter.net tell you how to perform this task, but one look at the code should tell you that it’s a complex task. (You can see the output from this example code here.)
jQuery makes it possible to perform the detection with relative ease. The following example shows one method to detect the name and version of the user’s browser. It relies on the latest 1.x version of jQuery, which is version 1.10.1 at the time of this writing. (You can find complete code for this example in the Chapter 06jQuery folder of the downloadable code as BrowserDetect.html.)<!DOCTYPE html> <html> <head> <title>Detect a Browser</title> <script src="http://code.jquery.com/jquery-latest.js"> </script> <script src="http://code.jquery.com/jquery-migrate-1.2.1.js"> </script> </head> <body> <h1>Browser Information</h1> <p id="name"></p> <script language="JavaScript"> var browser = $.uaMatch(navigator.userAgent).browser; $('p[id="name"]').html( "Browser Name: <span>" + browser + "</span>"); </script> <p id="version"></p> <script language="JavaScript"> $('p[id="version"]').html( "Version Number: <span>" + $.browser.version + "</span>"); </script> </body> </html>This is an HTML5 page, so it starts with the HTML declaration, . This example begins with a basic structure that includes the , ,
The code begins with the first