SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 73 | Next

Jonathan Snook, Aaron Gustafson, Stuart Langridge, and Dan Webb

"Accelerated DOM Scripting with Ajax, APIs, and Libraries"


Browser Sniffing vs. Object Detection
One of the biggest headaches you??™ll run into when using JavaScript is the varying degrees to
which browsers support or implement certain features. It??™s generally good practice to make
sure, as best you can, that the browser can complete the task at hand without spitting out
annoying error messages. There are a couple of ways to determine whether a browser is capable:
browser sniffing and object detection.
Browser sniffing is the way it used to be done. The browser has a special object called
navigator, within which are properties that describe the browser in some fashion or another.
Most browser sniffing comes from dissecting the userAgent property. Here??™s an example:
" Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; a
.NET CLR 1.1.4322; .NET CLR 2.0.50727)"
This is the user agent string for IE 7 on Windows XP. The problem is that browsers lie
because web site developers at one point used this string to determine whether a browser was
capable of using the site and would block out any user who wasn??™t using the ???right??? browser.
Therefore, when browser makers were about to release a new version, they??™d include a user
agent string that matched closely enough to get around these issues. IE pretended to be
Netscape; Opera pretended to be IE. Never mind the fact that in some browsers you can
change the string to anything you want. It really was a mess.


Pages:
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85