在沒有下載完成後使用的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>
恐怕你的問題不太合理。 「框架障礙」是什麼意思?另外,只要有鏈接到某個未知網站的鏈接,我就不會看到任何人使用該代碼並嘗試使用該代碼。人們可以理解......謹慎。 – 2009-09-24 08:14:15
你可以嘗試替換「chaozh.cn/Iheeo_pic/200961017195991087.bmp"/...;到一個大的BMP文件或頁面。 – Koerr 2009-09-24 08:56:12