2009-09-24 105 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