Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript function to reload a page every X seconds?

A couple of questions:

  • I've never really used JS listeners other than onclick and onkey events, so I wondered if someone could help me with what I need in order to reload the page every X seconds?

  • Secondly, the page contains bare minimum, literally just one input box. Do I still need to include the html head and body?

like image 369
Tom Avatar asked Oct 21 '10 22:10

Tom


People also ask

How do you refresh a page every 5 seconds?

setTimeout(function () { location. reload(1); }, 5000);

How do you refresh a page using JavaScript?

In JavaScript, you refresh the page using document. location. reload() . You can add the true keyword to force the reloaded page to come from the server (instead of cache).


1 Answers

You don't need Javascript for this simple function. Add in the page header:

<meta http-equiv="Refresh" content="300">

300 is the number of seconds in this example.

like image 98
Greg Hewgill Avatar answered Oct 12 '22 14:10

Greg Hewgill