【问题标题】:Settimeout works in chrome/webkit based browsers but not firefoxSettimeout 适用于基于 chrome/webkit 的浏览器,但不适用于 firefox
【发布时间】:2013-05-18 07:03:14
【问题描述】:

有人能解释一下为什么这个简单的代码可以在基于 webkit 的浏览器(甚至是我的安卓手机)中运行,但不能在 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>

【问题讨论】:

    标签: javascript google-chrome firefox webkit


    【解决方案1】:

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


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

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

    【讨论】:

    • 很高兴听到这个消息。 ;)
    猜你喜欢
    • 1970-01-01
    • 2013-08-27
    • 1970-01-01
    • 1970-01-01
    • 2020-08-26
    • 1970-01-01
    • 2020-03-22
    • 2018-09-08
    • 2014-11-17
    相关资源
    最近更新 更多