2013-05-18 72 views
0

有人可以解释为什么这个简单的代码可以在基于webkit的浏览器(甚至是我的android手机)中工作,但不能在Firefox上使用? (代码基本上刷新iframe中每1000毫秒(bash脚本回声到该文件))Settimeout适用于基于Chrome /浏览器的浏览器,但不适用于Firefox浏览器

此代码的网站是http://haenh.ddns.us/ui/content/servinfo,它是在嵌入:http://haenh.ddns.us/ui/?page_id=2(Firefox中的第一个环节我必须手动刷新而第二个链接显示纺纱绿色圆圈(表示它正在下载的内容)。在Chrome/WebKit的,这是令人耳目一新如预期)

<html> 
<head> 
<script> 
function a(){ 
document.close(); 
document.write('<br><p align="center"><iframe src="/serv.txt" width="700" height="2000" scrolling="no" frameborder="0"<> <p>Failed</p> </iframe></p><br><br>'); 
setTimeout('a()', 1000); 
// the old one was 15000 
} 
</script> 
</head> 
<body onLoad="a()"> 
<title>ServInfo</title> 
<br> 

JS is required. 

</body> 
</html> 

回答

2

呼叫document.close()document.write()而不是之前后,它会解决“总是加载“ 问题。


旁注:您还可以使用setTimeout(a, 1000);,而不是setTimeout('a()', 1000);。通过引用总是比使用eval别名更好。

而且我假设你已经知道在页面加载后使用document.write()会导致可怕的结果,这将会完全覆盖页面。我假设你故意使用它。

+0

旁注解决了这个问题:D – user1950278

+1

哦,很高兴听到这一点。 ')' –

相关问题