views:

2252

answers:

3

I am trying to autoreload my page after every 20 seconds. I am using JavaScript for this instead of the <meta>.

I have <body onload="SetTimer()"> and here is my JavaScript function

    function SetTimer(){
        setTimeout('window.location.replace(window.location.pathname)', 20000)
    }

Now my problem is I also pass a parameter within the querystring when this page is loaded first. But when the page relaods again (window.location.pathname does not include the parameter) hence I am not able to assign values to the labels on the page which is based on the parameters passed.

A: 

window.location will include the GET parameters that were that was passed.

function SetTimer(){ 
    setTimeout('window.location.replace(window.location)', 20000)
}

If you are submitting parameters through POST, the best method will probably be to create a form with hidden inputs for each parameter. Submit the form every twenty seconds.

ng.mangine
+1  A: 
 setTimeout('window.location.replace(window.location.href)', 2000);

did the trick

Mithil Deshmukh
Of course, taht will reload every 2 seconds...kind of annoying.
Darryl Hein
opps..that was meant to be 20 seconds..but the main issue of passing the paramters in the querystring everytime the page loads is solved using window.location.href instead of using window.location.pathname
Mithil Deshmukh
A: 

Simple page reload also does a trick

function SetTimer(){ 
    setTimeout('window.location.reload(true)', 20000)
}
alemjerus