Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript alert() advancing system time by 12ms

Here's a strange one:

I was working on synchronizing a JavaScript timer with a remote server and noticed my timer (based on the Date() object) was gaining about 12ms relative to my remote server on each page refresh. I narrowed it down to the JavaScript alert() function.

I created the following test and verified with 2 synchronized clocks that my system time will advance 1 second every 83-84 page refreshes. Has anybody seen this before?

<html> <head> </head> <body> <script type="text/javascript">   alert('hello'); </script> </body> </html> 

I'm using IE7 on XP SP3. Please tell me I'm not just going crazy!


EDIT:

I'm really not concerned about the accuracy of javascript timers. The real issue is that the JavaScript alert() function call is advancing my actual system time by 12ms.

like image 665
derek1284 Avatar asked Aug 05 '10 14:08

derek1284


People also ask

What happens when JavaScript runs the alert () function?

One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.

What is the difference between window alert and alert?

Difference between alert() and window. alert()window in JS is a global object, that means you can access it anywhere throughout your code. So, alert() becomes a global method / function. Therefore, you can call alert function of window object as window.

Why alert is not working in JavaScript?

The reason alert() does not work is because previously you have checked "prevent this page from creating additional dialoug" checkbox. lets take a look at this code. There will be two alert boxes if you run the code.

How an alert action works in JavaScript?

The JavaScript alert() method, also known as Window. alert() , displays an alert dialog box to a user. It accepts an optional message argument to display a message with an OK button to the user. Common uses for alert() are to let the user know an action was successful, or to display errors.


1 Answers

Well,

most likely you are crazy, since you are counting on JavaScript timers to be precise.

This explains a lot of that: http://ejohn.org/blog/accuracy-of-javascript-time/

like image 75
tomdemuyt Avatar answered Sep 21 '22 21:09

tomdemuyt