Browser detection in HTML - HTML

You can detect what kind of a browser a user is running by running a browserdetection script. This kind of script, along with some more finely tuned type of object detection described in the next section, is sometimes referred to as browser sniffing. At its simplest, a typical browser-detection script looks like this:

Note When using simple browser-sniffing scripts, you can replace the code in bold
in the preceding example with more complex tasks. In the next chapter, you’ll
see how to work with different CSS properties based on which browser a user
is using.

The Core Document Object Model used by ECMAScript (JavaScript).

The Core Document Object Model used by ECMAScript (JavaScript).

Object detection
Object detection is a more precise way of browser sniffing. It examines a browser’s support for various aspects of the object model. This avoids the potential for successfully checking a browser version but not checking to see if a browser actually supports a specific object property or method. For this reason, object detection is the preferred method for browser sniffing and is considered best practice. In addition, unless you’ve got the object model of all the different browsers memorized, it’s pretty hard to know which browser supports which object. It’s easier to just check and see if a browser supports a specific object’s properties or methods. The principles used in object detection are quite similar to those used in browser detection. You make use of JavaScript if statements to check a browser’s support for a named object’s properties or methods. If it does support the object, you execute some given code. For example, using regular expressions can be very handy in JavaScript, but not if your users’ browsers don’t support them. So you create a simple detection script to see if they do:


All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

HTML Topics