Prevent js alert() from pausing timers

后端 未结 8 903
花落未央
花落未央 2021-01-06 01:54

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 bo

8条回答
  •  自闭症患者
    2021-01-06 02:27

    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)

提交回复
热议问题