0

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

此代码的网站是http://haenh.ddns.us/ui/content/servinfo,它嵌入在:http ://haenh.ddns.us/ui/?page_id=2 (firefox I 中的第一个链接必须手动刷新,而第二个链接显示旋转的绿色圆圈(显示它正在下载内容)。在 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>
4

1 回答 1

2

调用document.close()之后document.write()而不是之前,它将解决“总是加载”的问题。


旁注:您也可以使用setTimeout(a, 1000);代替setTimeout('a()', 1000);. 传递引用总是比使用eval别名更好。

而且我假设您知道document.write()在页面加载后使用的可怕影响,这将完全覆盖页面。我假设您是故意使用它来达到这种效果的。

于 2013-05-18T07:06:20.437 回答