Greasemonkey script to reload the page every minute

牧云@^-^@ 提交于 2019-12-07 22:19:35

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!