Jump to content

keep frame from refreshing?


Smudly

Recommended Posts

I am working on a Traffic Exchange project. There are two frames. The top frame that shows the timer, and how many pages have been surfed, and the bottom page shows the next website for the user to view. When the timer hits 0, the user can hit the next button. I want the javascript timer to just reset without having the entire page refreshing. How can I do this?

 

<script type="text/javascript">

var time = 10;

function startCountdown(){
    var t = setTimeout("countdown()", 1000);
}

function countdown(){
    --time;
    if(time == 0){
        document.getElementById("countdown").innerHTML = "<a href='surf.php'>Next</a>";
    }else{
        document.getElementById("countdown").innerHTML = time;
        var t = setTimeout("countdown()", 1000);
    }
}


</script>

 

 

Link to comment
https://forums.phpfreaks.com/topic/204228-keep-frame-from-refreshing/
Share on other sites

None of that code should refresh the page. If you reset your 'time' variable in your startCountdown() function, you can just call that when 'Next' is pressed and it will reset the countdown.

function startCountdown(){
    time = 10;
    var t = setTimeout("countdown()", 1000);
}

 

You might want to use setInterval() so that it starts before the first second.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.