我的网页在IE中与兼容的查看模式有问题。我将向用户显示其浏览器处于兼容视图的警报,以便修复它。
我的问题是:有没有办法通过java脚本获得兼容的视图状态(打开或关闭)?
答案 0 :(得分:1)
<meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE" />
这会禁用兼容性视图
答案 1 :(得分:1)
document.compatMode可用于检查兼容性模式,并且显然适用于跨浏览器(通过IE,Chrome,Firefox验证):
例如,标准模式:
<!DOCTYPE html>
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge"/>
<title></title>
<script>
window.onload = function() {
var navigator = window.navigator;
info.firstChild.data =
"\n navigator.userAgent: " + navigator.userAgent +
"\n document.compatMode: " + document.compatMode;
}
</script>
</head>
<body>
<pre id="info"> </pre>
</body>
输出:
navigator.userAgent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0) document.compatMode: CSS1Compat
兼容模式:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "">
<head>
<title></title>
<script>
window.onload = function() {
var navigator = window.navigator;
info.firstChild.data =
"\n navigator.userAgent: " + navigator.userAgent +
"\n document.compatMode: " + document.compatMode;
}
</script>
</head>
<body>
<pre id="info"> </pre>
</body>
输出:
navigator.userAgent: Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2; WOW64; Trident/6.0; .NET4.0E; .NET4.0C; .NET CLR 3.5.30729; .NET CLR 2.0.50727; .NET CLR 3.0.30729; Media Center PC 6.0; Tablet PC 2.0) document.compatMode: BackCompat