interviews.dotnetthread.com

↑ Grab this Headline Animator

Monday, April 20, 2009

Detecting IE6, IE7 and Google chrome in Javascript.

Some times we need to detect the browser used by end user in Javascript and wants to apply browser specific actions like styles javascript. As the way javascript and styles is interpreted is different in different browser.

In order to detect IE6 in javascript you can use the below code


<script>
var IE6 = false /*@cc_on || @_jscript_version < 5.7 @*/;
if(IE6)
{
// Implement browser specific activities for IE6
}
</script>


In order to detect IE7 in javascript you can use the below code


<script type='text/javascript'>
if((document.all))
{
if((navigator.appVersion.indexOf("MSIE 7.")!=-1))
{
// Implement browser specific activities for IE7
}
}
</script>


In order to detect Google Chrome in javascript you can use the below code


<script type='text/javascript'>
var is_chrome = navigator.userAgent.toLowerCase().indexOf('chrome') > -1;
if(is_chrome)
{
// Implement browser specific activities for Google Chrome
}
</script>

Submit this story to DotNetKicks

1 comment:

Post a Comment

Post your comments/questions/feedback for this Article.

 

Latest Articles