0 (9|9)

JavaScript Browser Detection

Navigator Object

There are two big objects in the browser’s window. The first is document, which contains all inside the window. All information about opened tab is in the big second object - window. To watch the properties and functions of that object you can use ‘in’ operator: for(var prop in window). One of the properties is navigator object(link). This is object we need. It contains its own functions and attributes. The first attribute, which contains the name of the web browser application, is appName.

var appname = window.navigator.appName

And there is an attribute, where all the information about web browser is stored. It is window.navigator.userAgent. It contains the version, the name and the other main information of web browser.

Navigator's attribute Meaning
userAgent The main information of the browser. Contains the name of application, name of browser platform and the version
appCodeName attributes show the main information about the web browser application
browserLanguage shows the language of browser
cookieEnabled shows enabled cookies or not. Cookie is the storage of some data on the client side
platform shows what platform is used for application

Why Should You Detect The Browser?

The javascript syntax is the same for all of the browsers. But a client side script is different. The objects document and window have not same attributes and its values. For example Internet Explorer 8 hasn’t document.getElementsByClassName() function. This method gets all the tags, which have the class we need. This difference between browsers causes problems with script’s creation in a web development.

Javascript Browser detection

Added 14.09.2012
By Sergej
serjcat said
Browser detection including chrome http://divhack.com/node/70
Added: 23.10.2012 23:40:57
Your name
Add comment
Don't miss:
Most popular
The best

Web development 2011-2012 ©