我有一个应用程序在某些情况下会导致 IE8 弹出兼容性消息并以兼容模式重新加载:
a problem displaying caused internet explorer to refresh the webpage using compatibility view
这种情况很少见,据我所知不会因为元标记而发生。它作为对更改 DOM 的用户操作的响应而发生。这与以下问题相同:https://superuser.com/questions/215281/how-do-i-stop-i-e-jumping-into-compatability-view ,但我的问题是:是什么类型的事情导致了这种情况,以帮助修复它。
换句话说,看这个网站thesitewizard.com ,其中IE8兼容模式的第三个原因描述为:
and, on occasion, for some other unfathomable, undocumented reason, on pages that are validated as standards-compliant (or, at least, it does this in Release Candidate 1).
问题是:有哪些深不可测、未记录的原因?
最佳答案
经过长时间的调试(使用老式警报来查明失败的地方),这条看似无害的 dom 操作线是罪魁祸首:
document.getElementById("literal"+varValue).style.display = "none";
这里没有错误,显然找到了元素(即,这不是普通的空指针)。
这是一个大型应用程序,围绕这段代码进行了很多工作。我将其切换为以下内容,这显然已经阻止了这个问题:
setTimeout(function(){
var layoutEl = document.getElementById("literal"+varValue);
if (layoutEl)
layoutEl.style.display = "none";
},10)
关于html - 哪些具体的事情会导致 IE8 触发兼容模式?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9006845/