Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to detect Internet Explorer 6 using JavaScript?

What is the best way to detect Internet Explorer 6 using JavaScript?

If browser == IE6 {
    alert('hi');
}
like image 790
TIMEX Avatar asked Feb 04 '10 00:02

TIMEX


People also ask

Does Internet Explorer use JavaScript?

As with most modern browsers, Internet Explorer supports JavaScript, which is enabled by default to allow users view dynamic interactions like display ads and animations on web pages.

How can I tell if Internet Explorer is being used?

To detect whether the current browser is Internet Explorer, you can make use of the navigator. userAgent property. The userAgent property returns the value of the user-agent header sent by the browser to the server. It contains information about the name, version, and platform of the browser.

How can you detect the client's browser name in JavaScript?

You can use the navigator. appName and navigator. userAgent properties. The userAgent property is more reliable than appName because, for example, Firefox (and some other browsers) may return the string "Netscape" as the value of navigator.


3 Answers

Conditional comments are a good alternative:

<!--[if IE 6]>
<script>
var everythingIsBroken = true;
</script>
<![endif]-->

Edit: If you're still looking to support IE 6 in 2017 or after ... well my heart goes out to you. The answer to this question in 2017 is really not to worry about IE 6. It's not a supported browser anymore. Any operating system that can run this browser and the browser itself are not getting security updates anymore. This means users using this software are at great risk of being exploited. This is a big problem for people who can't afford to upgrade.

like image 94
Bjorn Avatar answered Oct 08 '22 03:10

Bjorn


At the risk of actually answering the question that was asked (and assuming for a moment the asker has a good reason to specifically detect IE6):

if (/\bMSIE 6/.test(navigator.userAgent) && !window.opera) {
  // yep, browser claims to be IE6
}
like image 29
thomasrutter Avatar answered Oct 08 '22 03:10

thomasrutter


  var ua = window.navigator.userAgent;
  var msie = ua.indexOf ( "MSIE " );

  if ( msie > 0 )      // If Internet Explorer, return version number
     return parseInt (ua.substring (msie+5, ua.indexOf (".", msie )));
  else                 // If another browser, return 0
     return 0;

Source : http://support.microsoft.com/kb/167820

like image 7
Hannoun Yassir Avatar answered Oct 08 '22 02:10

Hannoun Yassir