20 November 2009

How to do autorefresh using javascript

  1. If you want to refresh your page automatically after loading the page
    <html>
    <head>
    <script type="text/JavaScript">
    function timedRefresh(timeoutPeriod) {
    setTimeout("location.reload(true);",timeoutPeriod);
    }


    </script>
    </head>
    <body onload="JavaScript:timedRefresh(5000);">

    This page will refresh every 5 seconds. Here we are using the "onload" event to call our function. We are passing in the value '5000', which equals 5 seconds.
    </body>
    </html>
  2. If you want to refresh a page "on click", type the following code as:-

    <a href="javascript:location.reload(true)">Refresh this page</a>


1 comment: