Search code examples
javascriptgreasemonkeyreload

How to reload page within range of seconds using JavaScript


Simple question that I can't seem to find the answer to. I'd like to reload a webpage between every 5 and 20 second. How do I accomplish this using JavaScript? I know how to reload the page every x amount of seconds, but have no clue how to insert a range of time. I'm using Greasemonkey, if that's of any importance.


Solution

  • Just generate a random number between 5 and 20:

    var num = Math.round((Math.random() * 15) + 5);