4

I used to check it this way:

$.browser.msie && $.browser.version == 8

But it seems that $.browser has been removed from the later versinos of jQuery,

So,

How can I check that with just pure javascript?

I tried:

isIE8: navigator.appVersion.indexOf("MSIE 8") > 0

Wich seems to Do it, but it doesn't look that good and actually looks like it have many flaws...

Any better aproach?

Toni Michel Caubet
  • 19,333
  • 56
  • 202
  • 378

2 Answers2

3

This is longer than the one-liner you probably want, but safer than parsing the UA string, because it's based on actual behaviour (IE conditional comments): https://gist.github.com/paulirish/357741

Ronny
  • 4,295
  • 2
  • 24
  • 30
2

You could check if the SVG tag is supported. SVG was not supported in IE8 -> http://caniuse.com/#search=svg To the opposit, the DATA tag was introduced in IE8 -> http://caniuse.com/#search=data

So :

if (navigator.userAgent.toLowerCase().indexOf('msie') != -1) {
   if (!document.createElement('SVG').getAttributeNS) {
       if (document.createElement('DATA').getAttributeNS) {
           //the browser is defently IE8
        }
    }
}
davidkonrad
  • 83,997
  • 17
  • 205
  • 265