javascript Greasemonkey 脚本每分钟重新加载页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25484978/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Greasemonkey script to reload the page every minute
提问by John Smith
How to reload a page every 60 seconds?
如何每 60 秒重新加载一个页面?
My attempt:
我的尝试:
setTimeout (location.reload, 1 * 60 * 60);
I'm not sure what those numbers mean, or how to adapt them to reload after 60 seconds only.
我不确定这些数字是什么意思,或者如何使它们仅在 60 秒后重新加载。
回答by Aryess
setTimeout(function(){ location.reload(); }, 60*1000);
You have to pass a full function as first argument, and second is the time in millisecond. So in your case, 60 * 1000
你必须传递一个完整的函数作为第一个参数,第二个是以毫秒为单位的时间。所以在你的情况下,60 * 1000
回答by Quasimodo's clone
You may give a function name, since it is a callable, however, location.reload
is a method of the location
object. It is callable, but when it is executed by the timer, the this
context will not be the location object. This fact leads to an error.
你可以给一个函数名,因为它是一个可调用的,但是,它是对象的location.reload
一个方法location
。它是可调用的,但是当它被定时器执行时,this
上下文将不是位置对象。这个事实会导致错误。
The solutions are:
Write a simple anonymous function as a wrapper as already described in the accepted answer or
create a bound function of the reload method with location
as its this
context:
解决方案是:
编写一个简单的匿名函数作为包装器,如已接受的答案中所述,或者
创建一个 reload 方法的绑定函数location
作为其this
上下文:
setTimeout(location.reload.bind(location), 60000);
回答by Philipp
Looking at a documentationmight help you. The parameters to the setTimeout function are the action which is performed and the number of milliseconds until this happens. 1 * 60 * 60
is 3600ms or 3.6 seconds. A timespan of 60 seconds would be 60000.
查看文档可能对您有所帮助。setTimeout 函数的参数是执行的操作以及执行此操作之前的毫秒数。1 * 60 * 60
是 3600 毫秒或 3.6 秒。60 秒的时间跨度将是 60000。