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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.