Search code examples
javascriptjqueryrefreshcountdown

Jquery refresh page after countdown hits 0


I am using Keith Wood Jquery Countdown Timer (http://keith-wood.name/countdown.html) and I wanted to make it so that when the timer hits 0 the page would refresh. unfortunately I couldn't make this happen.. Here is my code:

$(function () {
        var now = new Date($.now());
        var austDay = new Date();
        austDay = new Date(//php stuff to get the date from the database..);
        $('#defaultCountdown').countdown({until: austDay, format: 'DHMS'});
        if (austDay <= now) {
            location.reload();
        }
});

Thanks in advance.


Solution

  • According to the documentation that you linked to, you can specify an onExpiry callback for when the countdown gets to zero. You then supply a function that can do whatever you like at that moment:

    $('#defaultCountdown').countdown({
        until: austDay,
        format: 'DHMS',
        onExpiry: function() { location.reload(); }
    });
    

    (I haven't tested the above code, but it seems pretty clear in the doco.)