Greasemonkey script to reload the page every minute

淺唱寂寞╮ 提交于 2019-12-06 06:08:17
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

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);

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.

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