Check if IE8 with pure Javascript [duplicate]

只谈情不闲聊 提交于 2019-12-10 16:38:05

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!