问题
How to reload a page every 60 seconds?
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.
回答1:
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
回答2:
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.
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:
setTimeout(location.reload.bind(location), 60000);
回答3:
Looking at a documentation might 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.
来源:https://stackoverflow.com/questions/25484978/greasemonkey-script-to-reload-the-page-every-minute