我正在尝试构建一个页面编辑器。一个问题让我在 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>
它只是检查以Mozilla方式或IE方式设置“designMode”是否合适。当页面加载时,会弹出一个“Mozilla”;点击 iframe 区域,焦点在 iframe 上,我可以用键盘输入。
这看起来不错,但是当我注释掉“alert("mozilla"); ”,它不起作用。如 FireBug 所示,“designMode”为“Off”。
这太有线了。为什么警报会影响 DOM 和 javascript?顺便说一句,我的 Firefox 是 3.0.6。