在没有下载完成后使用的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