0
votes

Good day,

I'm creating a basic webpage/game where I need a countdown timer. I have found http://keith-wood.name/countdown.html Timer, which is great for what I need. However the game goes from page to page based on varying rounds. ie.) On each new round the time will of course restart.

As I'm using below for the one minute countdown. How can I implement the timer that it travels across different page, is this the recommended way to solve this problem?

I'm thinking that I could use session, for the countdown.

$(document).ready(function () {
    $('#timer').countdown({
        until: +60,
        compact: true
    });
});
1

1 Answers

1
votes

You can set the until time in a cookie and set the until option in the countdown to that value. Then it will be persisted across requests with a consistent final value.

There is a jQuery Cookie library that can be helpful for you there: https://github.com/carhartl/jquery-cookie

You can also set the cookie expiration to expire at the same time so that it automatically gets deleted at the correct time. That is most useful if your application changes once the timer is up.