Javascript – Prevent js alert() from pausing timers

javascripttimer

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?

Best Solution

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)