Smudly Posted June 8, 2010 Share Posted June 8, 2010 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> Quote Link to comment Share on other sites More sharing options...
lemmin Posted June 8, 2010 Share Posted June 8, 2010 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.