且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

IE10及以下浏览器检测

更新时间:2022-10-16 16:26:58

在Internet Explorer 11中,Microsoft取出MSIE,现在它看起来像这样:

In Internet Explorer 11, Microsoft took out the "MSIE", so it now looks like this:

Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko

所以你可以检查是否存在MSIE到告诉你它是否是旧版本。

So you could just check for the presence of "MSIE" to tell you if it's an old version.

if (navigator.userAgent.indexOf("MSIE") >= 0) {
    document.write("You are using an unsupported version of Internet Explorer. Please upgrade to Internet Explorer 11 or use a different web browser.");
}

请注意,如果Internet Explorer处于兼容性视图中,并且您还没有指定了一个X-UA-Compatible标头,它会将自己标识为IE 7,并且表现得像它一样。

Just note that if Internet Explorer is in compatibility view, and you haven't specified an X-UA-Compatible header, it will identify itself as IE 7 and act like it too.