Detecting Browsers using Java Script

Hi All,

Although it is not a rocket science to get the browser details using any technology script, but i will show a very Object oriented way to display the browser details using java script.

Step 1: Create one JS file, Name it CheckBrowser.js

Step 2: Write the below code in the file.

function IsBrowser(){
var agt=navigator.userAgent.toLowerCase();
this.major = parseInt(navigator.appVersion);
this.minor = parseFloat(navigator.appVersion);
this.nav  = ((agt.indexOf(‘mozilla’)!=-1) && ((agt.indexOf(‘spoofer’)==-1)  && (agt.indexOf(‘compatible’) == -1))); // FireFox/Mozilla

// add your browsers detection code here.
// e.g this.ie=

}

Step 3: Add the js in the Html/JSP/ASP/PHP file.
// <![CDATA[
javascript” >
// ]]>

Step 4: Invoke the function in Object oriented way

var is = new IsBrowser();
alert(is.nav);


Thanks
R Vashi

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s