2009-09-24 104 views
1

在没有下载完成后使用的innerHTML会导致页面加载的iframe障碍Firefox的错误的innerHTML的iframe标签

在下面的例子前,先点击“openA”(谷歌网页),然后“ openB“(雅虎页面),然后是”openA“,然后在错误的yahoo页面上显示一个窗口。

在铬和IE中的BUG不存在。

如何避免此问题?

错误示例代码:

<HTML> 
<HEAD> 
<script> 
function openA(){ 
    var winObj=document.getElementById("win_A"); 
    if(winObj==null){ 
     winObj=document.createElement('div'); 
     winObj.id="win_A"; 
     winObj.style.position="absolute"; 
     winObj.style.left="0"; 
     winObj.style.top="200"; 
     winObj.style.height="300"; 
     winObj.style.width="300"; 
     winObj.style.border="1px solid red"; 
     document.body.appendChild(winObj); 
    } 
    document.getElementById("win_A").innerHTML=("<iframe src='http://www.google.com/'></iframe>"); 
} 
function openB(){ 
    var winObj=document.getElementById("win_B"); 
    if(winObj==null){ 
     winObj=document.createElement('div'); 
     winObj.id="win_B"; 
     winObj.style.position="absolute"; 
     winObj.style.left="350"; 
     winObj.style.top="200"; 
     winObj.style.height="300"; 
     winObj.style.width="300"; 
     winObj.style.border="1px solid red"; 
     document.body.appendChild(winObj); 
    } 
    document.getElementById("win_B").innerHTML=("<iframe src='http://www.yahoo.com/'></iframe>"); 
} 
</script> 
</HEAD> 

<BODY> 
    <INPUT TYPE="button" VALUE="openA" ONCLICK="openA()"><INPUT TYPE="button" VALUE="openB" ONCLICK="openB()"> 
    <script>document.write("<iframe src=\"http://www.chaozh.cn/Iheeo_pic/200961017195991087.bmp?"+new Date()+"\"></iframe>");</script> 
    <INPUT TYPE="button" VALUE="Reload" ONCLICK="location.href=location.href;"> 
</BODY> 
</HTML> 

</pre> 
+0

恐怕你的问题不太合理。 “框架障碍”是什么意思?另外,只要有链接到某个未知网站的链接,我就不会看到任何人使用该代码并尝试使用该代码。人们可以理解......谨慎。 – 2009-09-24 08:14:15

+0

你可以尝试替换“chaozh.cn/Iheeo_pic/200961017195991087.bmp"/...;到一个大的BMP文件或页面。 – Koerr 2009-09-24 08:56:12

回答

0

工作正常,我在FF 3.5.3

托管了大量点击的重现它。 似乎是FireFox中的一个bug。

而不是重新创建iframe每次你可以设置它的.src

+0

你在firefox下载的时候已经在点击“openA”和“openB”吗? 必须在“下载”时出现BUG – Koerr 2009-09-24 08:12:47

+0

我的firefox是3.5.3。 – Koerr 2009-09-24 08:13:19

+0

尝试将“http://www.chaozh.cn/Iheeo_pic/200961017195991087.bmp” 替换为大的BMP文件或页面。 – Koerr 2009-09-24 08:14:12