views:

154

answers:

1

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.

+1  A: 

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/

T.

tomdemuyt
But the OP claims that his *system time* gets altered. This is something else, isn't it?
Pekka
What I'm talking about isn't a delay in my javascript timer -- My actual system time is being modified by the execution of the alert() function. I've refreshed this page a couple hundred times and now when I pull up my system clock it is 5 seconds ahead of my watch that I had just synchronized with my system.
Derek
@Derek: I always knew that JavaScript is **evil** ;) (*sorry for not providing a more useful comment*).
Felix Kling