JavaScript Alert() 将系统时间提前 12 毫秒
这是一个奇怪的情况:
我正在努力将 JavaScript 计时器与远程服务器同步,并注意到我的计时器(基于 Date()
对象)在每次页面刷新时相对于远程服务器增加了大约 12 毫秒。我将其范围缩小到 JavaScript alert()
函数。
我创建了以下测试并使用 2 个同步时钟验证我的系统时间每刷新 83-84 次页面就会前进 1 秒。有人见过这个吗?
<html>
<head>
</head>
<body>
<script type="text/javascript">
alert('hello');
</script>
</body>
</html>
我在 XP SP3 上使用 IE7。请告诉我我不是疯了!
编辑:
我真的不关心 javascript 计时器的准确性。真正的问题是 JavaScript alert()
函数调用将我的实际系统时间提前了 12 毫秒。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好吧,
很可能你疯了,因为准确地说你依赖的是 JavaScript 计时器。
这解释了很多内容: http://ejohn.org/blog/accuracy- of-javascript-time/
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/