有人可以解释一下为什么这个简单的代码可以在基于 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.write()
之后而不是之前调用 document.close()
,它将解决“始终加载”问题。
附注:您还可以使用 setTimeout(a, 1000);
代替 setTimeout('a()', 1000);
。传递引用总是比使用 eval
别名更好。
我假设您知道在页面加载后使用 document.write()
会产生可怕的影响,这将完全覆盖页面。我假设您是故意使用它来达到这种效果。
关于javascript - Settimeout 适用于基于 chrome/webkit 的浏览器,但不适用于 Firefox,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16621636/