views:

41

answers:

4

Hi guys, a couple of questions- ive never really used JS listeners other than onclick and on key events, so i wondered if someone could help me with what i need 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?

+1  A: 

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.

Greg Hewgill
+1  A: 

To reload the page after 5 seconds (5000 milliseconds) using javascript, add the following to the bottom of the page:

<script type="text/javascript"
  setTimeout(function () { location.reload(true); }, 5000);
</script>

As Greg Hewgill notes, you can also accomplish this with the meta refresh tag:

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

Strictly speaking, you do still need <html> and <body> tags. Some browsers may still render the page correctly without them, but your are safest to include them.

pkaeding
A: 

use a timer: http://www.elated.com/articles/javascript-timers-with-settimeout-and-setinterval/ and usee ajax to reload if it is dynamic

user1111111
A: 

To your second question, ye you definitely do!!

Toy your first question check this out:

http://www.javascriptkit.com/script/script2/autofresh.shtml

Or this to do it without javascript:

http://webdesign.about.com/od/metataglibraries/a/aa080300a.htm

It does what you asked and is very easy to configure!

Trufa