Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent js alert() from pausing timers

So I made some timers for a quiz. The thing is, I just realized when I put

javascript: alert("blah");

in the address, the popup alert box pauses my timer. Which is very unwanted in a quiz.

I don't think there is any way to stop this behaviour... but I'll ask anyway.

If there is not, mind suggesting what should I do?

like image 999
syaz Avatar asked Oct 13 '08 15:10

syaz


2 Answers

Never, ever rely on javascript (or any other client-side time) to calculate elapsed times for operations done between postbacks, or different pages.

If you always compare server dates, it will be hard for people to cheat:

  1. first page request, store the server time
  2. ping with javascript calls each N seconds, compare the 2 server times, and return the elapsed (just for show)
  3. when the user submits the form, compare the 2 server times, calculate the elapsed time, and discard the ones which took too long (ie: possible cheaters)
like image 84
Filini Avatar answered Sep 28 '22 19:09

Filini


Apparently the preview rendering differs from the posted rendering. This paragraph is here to make sure the next two lines show up as code.

// Preserve native alert() if you need it for something special
window.nativeAlert = window.alert;

window.alert = function(msg) {
    // Do something with msg here. I always write mine to console.log,
    // but then I have rarely found a use for a real modal dialog,
    // and most can be handled by the browser (like window.onbeforeunload).
};
like image 34
eyelidlessness Avatar answered Sep 28 '22 20:09

eyelidlessness