Javascript 为什么弹出式警报会影响;设计模式;?
我正在尝试构建一个页面编辑器。在firefox中有一个问题让我抓狂 页面代码如下:Javascript 为什么弹出式警报会影响;设计模式;?,javascript,firefox,alert,designmode,Javascript,Firefox,Alert,Designmode,我正在尝试构建一个页面编辑器。在firefox中有一个问题让我抓狂 页面代码如下: <body> <iframe WIDTH=200 HEIGHT=200 id="myEditor"></iframe> <script> function getIFrameDocument(sID){ // if contentDocument exists, W3C compliant (Mozilla) if (doc
<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>
函数getIFrameDocument(sID){
//如果存在contentDocument,则符合W3C标准(Mozilla)
if(document.getElementById(sID.contentDocument){
alert(“mozilla”);//注释掉这一行,它就不起作用了
return document.getElementById(sID).contentDocument;
}否则{
//即
警惕(“IE”);
//返回文档.getElementById(sID);
返回文档。帧[sID]。文档;
}
}
getIFrameDocument(“myEditor”).designMode=“On”;
它只是检查以Mozilla方式或IE方式设置“设计模式”是否合适。当页面加载时,会弹出一个“Mozilla”;单击iframe区域,焦点在iframe上,我可以用键盘输入
这看起来不错,但当我注释掉“alert”(“mozilla”);”这行时,它就不起作用了。如FireBug所示,“设计模式”为“关闭”
这是如此有线。为什么警报会影响DOM和javascript?
顺便说一句,我的Firefox是3.0.6。因为警报会给iframe加载时间。只有在加载iframe文档后,才应将设计模式设置为“开”:
iframe.onload = function() {
doc.designMode = "on";
};
谢谢修复使它工作!“加载iframe后可以打开设计模式”只适用于Firefox,对吗?似乎IE没有这样的限制。我不太记得这件事了。上次我在玩designMode时,我在两种浏览器中都应用了“onload”,但是的,我第一次在FF中观察到它。无论如何,我确实记得IE中动态生成的iFrame有问题。所以也要小心这些。