<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <title>Page Timed Reload !</title>
    <script type="text/javascript">
    
    var counter = 1, nor = 0;
    
    function startCounter(){
        document.myForm.myText.value = counter++;
        if (counter == 15) {
            document.location.reload();
            nor++;
            document.write("The page has been reloaded ") + nor + document.write(" times !")
        }
    }
    var myInterval = window.setInterval("startCounter()", 1000)
    
    </script>
    </head>
    
    <body onload="startCounter()">
    <form name="myForm">
      <!-- THE TIMER BOX -->
      <input type="text" size="20" value="" name="myText" />
    </form>
    </body>
</html>

I want this page to be reloaded every 15 seconds, and show the number of reloads till that time.
I also wish to show a box where the timer is shown !

I have not been able to completely do it ... I need help in this !!

Recommended Answers

All 5 Replies

Apanimesh,

You appear not to have a mechanism for propagating the count value from refresh to refresh.

You can't maintain the counter on the page, either in the DOM or in javascript, because the whole environment gets wiped out when the page is refreshed.

There are two basic ways to do this.

HINT (I expect): Think about what your tutor was teaching you before he/she set the problem.

Airshow

Oh !
Well .... I am sorry, but I thought of this problem myself ... I do not have a tutor or anything, I am learning this on my own.
Actually, there is a cricket score website where the page refreshes after every 15 seconds and the score is updated automatically.

So, I would be glad if you could tell me the two basic ways !!!

Apanimesh,

Doh! I was wrong about that then.
Tutors please note - this would be a good problem for your pupils.

Method 1: Put the value into the "search" part of the url. In the refreshed page, read the value back from the location object. The following utilities will help you understand what I mean (and will do part of the job):

Method 2: Cookie

Airshow

Member Avatar for diafol

do you need the whole page reloaded or just a part of it? A total reload every 15 seconds sounds a bit odd to me. Why not just use ajax to update one bit?

<meta http-equiv="refresh" content="15;pagename.html" />

put this code in your <head> section. This will help to refresh your page every 15 seconds.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.