问题
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?
回答1:
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
回答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
}
}
}
来源:https://stackoverflow.com/questions/21855378/check-if-ie8-with-pure-javascript