为什么弹出警报可以影响“的designMode”?
-
09-09-2019 - |
题
我expreimenting建立一个网页编辑器。一个问题只是让我抓狂的Firefox。
在页面代码如下:
<body>
<iframe WIDTH=200 HEIGHT=200 id="myEditor"></iframe>
<script>
function getIFrameDocument(sID){
// if contentDocument exists, W3C compliant (Mozilla)
if (document.getElementById(sID).contentDocument){
alert("mozilla"); // comment out this line and it doesn't work
return document.getElementById(sID).contentDocument;
} else {
// IE
alert("IE");
//return document.getElementById(sID);
return document.frames[sID].document;
}
}
getIFrameDocument("myEditor").designMode = "On";
</script>
</body>
它只是检查它是否approprate设置在Mozilla方式或IE方式“的designMode”。页面加载时,一个“Mozilla的”弹出;点击iframe的区域,而重点是在iframe和我可以用键盘输入。
这看起来不错,但是当我注释掉行 “警报( “Mozilla浏览器”); 的”,它不工作。该“的designMode”是为“Off”萤火节目。
这是这样的有线。为什么警报会影响DOM和JavaScript? 顺便说一句,我的Firefox是3.0.6。
解决方案
由于警报给出的IFRAME时间来加载。你应该设置的designMode为“on”的iframe文件已加载之后才:
iframe.onload = function() {
doc.designMode = "on";
};
不隶属于 StackOverflow