在我的网站上,在Windows Server 2012上使用了jquery / bootstrap / knockout IE10(尽管在Win2008上发生了相同的错误,但大多数都是用它测试过的)IE会抛出一个错误,说明增强安全配置阻止来自about:blank
的内容
IE认为来自about:blank
?
我在页面上放置了<noscript>
,但页面本身不在正常的安全区域中,但是取消选中Continue to prompt...
的人永远不会看到任何错误和部分错误网站将停止工作,而其他人工作正常。
答案 0 :(得分:4)
逐行调试后,我发现以下条件组合会导致错误。这可能不是唯一的原因,但它也允许我编写向用户显示警告的代码。
// 1. create an element but do not add it to the DOM
var elem = document.createElement("div");
// 2. set its innerHTML to something that contains script.
// in this line IE shows the error although the code continues.
elem.innerHTML = "<span onclick=\"alert()\">aa</span>";
// 3. add to the DOM
document.body.appendChild(elem);
// in order to fix the issue, move item #3 right after #1.
如果在设置.innerHTML
之前将元素添加到DOM中,则可以正常工作。需要注意的是代码实际完成,如果你检查.innerHTML
,你实际上会看到onclick
处理程序完好无损。问题是,当您单击元素时,它将不会被解析,也不会被执行。
因此,我使用此方法创建了以下代码,向用户显示警告。
var test = document.createElement("div");
test.innerHTML = "<span onclick=\"window.B264E0BD67794ED9949FCF91D654F54F=1;\"></span>";
test.getElementsByTagName("span")[0].click();
if (!window.B264E0BD67794ED9949FCF91D654F54F)
alert("Your browser is configured to use Enhanced Security Configuration which is not compatible with this website.");