Monday, October 4, 2010

How to detect browser using javascript

we can use navigator.userAgent to detect the type/name of current browser and perform compatibility operations according to it:

below is javascript code so put it in script tag


function DetectBrowser()
{

var val = navigator.userAgent.toLowerCase();



if(val.indexOf("firefox") > -1)

{

isFF = true;

}

else if(val.indexOf("opera") > -1)

{
isOP = true;

}

else if(val.indexOf("msie") > -1)

{

isIE = true;

}

else if(val.indexOf("safari") > -1)

{

isIE = true;

}
}

Share This!


1 comment:

Anonymous said...

Sorry for my bad english. Thank you so much for your good post. Your post helped me in my college assignment, If you can provide me more details please email me.

Powered By Blogger · Designed By Seo Blogger Templates