gpt4 book ai didi

javascript - IE11通过javascript检测兼容性 View 是否打开

转载 作者:行者123 更新时间:2023-12-03 13:22:08 25 4
gpt4 key购买 nike

当我通过 javascript 在网站上时,有谁知道如何检查 IE 11 兼容模式是否打开?

我将 url 添加到列表兼容性 View 设置中。但是当我这样做时

navigator.userAgent

在开发者工具中,它返回

Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; InfoPath.3; rv:11.0) like Gecko



查看微软网站( http://msdn.microsoft.com/en-us/library/ie/hh869301(v=vs.85).aspx),它说

The compatible ("compatible") and browser ("MSIE") tokens have been removed.



任何有关通过 javascript 检测页面是否使用兼容性 View 的帮助都会非常有帮助。提前致谢。

最佳答案

已解决

在自己寻找这个问题的答案时,我在另一个线程中找到了 Nenad Bulatovic 的这个解决方案,但他的回答没有被标记为正确答案。我在 IE11 中对此进行了测试并降级到 IE5,发现它适用于 IE7-IE11,这很棒。我想在这里分享它,以防其他人发现它有用。

iecheck.js

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
<!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>

来源: Detect IE10 compatibility mode

关于javascript - IE11通过javascript检测兼容性 View 是否打开,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27912296/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com