[英]Why doesn't this setTimeout-based code work in Firefox with a small timeout (works in Internet Explorer/Chrome)?
[英]Settimeout works in chrome/webkit based browsers but not firefox
有人可以解释为什么这个简单的代码在基于webkit的浏览器(甚至我的Android手机)中工作,但在Firefox上却没有? (代码基本上每1000毫秒刷新一次iframe(bash脚本回显到该文件))
这段代码的网站是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>
调用document.close()
后document.write()
,而不是之前,它会解决“总是装”的问题。
附注:您还可以使用setTimeout(a, 1000);
而不是setTimeout('a()', 1000);
。 传递引用总是比使用eval
别名更好。
我假设您已经意识到在页面加载后使用document.write()
的可怕影响,这将完全覆盖页面。 我假设你故意使用它来达到这个效果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.