首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >检测IE10兼容模式

检测IE10兼容模式
EN

Stack Overflow用户
提问于 2013-02-10 05:08:09
回答 4查看 24.4K关注 0票数 14

我有一些IE 10和其他IE版本的特定代码路径。如果IE10在兼容模式下运行,则浏览器版本设置为7.0。有没有一种方法可以使用JavaScript/JQuery来检测它是否是IE10,而不考虑标准/兼容模式?

EN

回答 4

Stack Overflow用户

回答已采纳

发布于 2013-02-19 10:34:36

用户代理字符串中的三叉树值指示正在运行的IE的实际版本。

票数 6
EN

Stack Overflow用户

发布于 2013-02-11 17:32:01

您可以使用navigator.userAgent字符串来检测这一点,例如

"Mozilla/4.0 (兼容;MSIE7.0;Windows NT 6.2;WOW64;Trident/6.0;.NET4.0E;.NET4.0C;InfoPath.3;.NET CLR 3.5.30729;.NET CLR 2.0.50727;.NET CLR 3.0.30729;Zune 4.7)“

三叉树/6.0表示IE10

MSIE 7.0表示兼容模式

更多细节:https://stackoverflow.com/a/5825518/255654

票数 21
EN

Stack Overflow用户

发布于 2015-08-07 21:46:54

这应该可以在MSIE的检测兼容模式下工作。

iecheck.js

代码语言:javascript
运行
复制
function trueOrFalse() {
    return true;
}

function IeVersion() {
    //Set defaults
    var value = {
        IsIE: false,
        TrueVersion: 0,
        ActingVersion: 0,
        CompatibilityMode: false
    };

    //Try to find the Trident version number
    var trident = navigator.userAgent.match(/Trident\/(\d+)/);
    if (trident) {
        value.IsIE = true;
        //Convert from the Trident version number to the IE version number
        value.TrueVersion = parseInt(trident[1], 10) + 4;
    }

    //Try to find the MSIE number
    var msie = navigator.userAgent.match(/MSIE (\d+)/);
    if (msie) {
        value.IsIE = true;
        //Find the IE version number from the user agent string
        value.ActingVersion = parseInt(msie[1]);
    } else {
        //Must be IE 11 in "edge" mode
        value.ActingVersion = value.TrueVersion;
    }

    //If we have both a Trident and MSIE version number, see if they're different
    if (value.IsIE && value.TrueVersion > 0 && value.ActingVersion > 0) {
        //In compatibility mode if the trident number doesn't match up with the MSIE number
        value.CompatibilityMode = value.TrueVersion != value.ActingVersion;
    }
    return value;
}

iecheck.html

代码语言:javascript
运行
复制
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Testing IE Compatibility Mode</title>
    <script src="iecheck.js" type="text/javascript"></script>
</head>
<body>
<div id="results">Results: </div>
</br>
<script type="text/javascript">

var ie = IeVersion();

document.write("IsIE: " + ie.IsIE + "</br>");
document.write("TrueVersion: " + ie.TrueVersion + "</br>");
document.write("ActingVersion: " + ie.ActingVersion + "</br>");
document.write("CompatibilityMode: " + ie.CompatibilityMode + "</br>");

</script>
</body>
</html>
票数 12
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14791619

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档