0

I have a timer to refresh the page, and it's working:

updateCountdown = function() {
    if (Variables.Seconds == Infinity) {
    } else if (Variables.Seconds == 0) {
        $countdown.text('Bam!');
        window.location.replace(Variables.PageName);
    } else {
        $countdown.text(Variables.Seconds--);
        setTimeout(updateCountdown, 1000);
    }
};

Then I have this:

document.onkeydown=function(e) {

    if (e.which==27) {
        Variables.Seconds = 0;
        updateCountdown();
    }
};

When I press escape, then $countdown.text says 'Bam!', but the page does not refresh like it does whenever Variables.Seconds normally decrements to 0.

Phillip Senn
  • 46,771
  • 90
  • 257
  • 373

1 Answers1

4

You might need to do return false; after you call updateCountdown(); to cancel the default action of Escape.

   document.onkeydown=function(e) {

        if (e.which==27) {
            Variables.Seconds = 0;
            updateCountdown();
            return false;
        }
    };

If you are using other javascript libraries this post might be of help.

Community
  • 1
  • 1
LoveGandhi
  • 402
  • 4
  • 13