English 中文(简体)
在网络上实现“高于毫秒”精度定时器的可能性(最好使用javascript)
原标题:Possibility of achieving a "higher-than millisecond" precision timer on the web (preferrably using javascript)

我不需要微米或纳米精度,1毫秒的精度就足够了。

有没有一种合理可靠的方法可以做到这一点?它不是一个关键的应用程序,由于最终的CPU频率缩放或类似的事情而产生的零星错误是可以接受的。我只是想知道这是否可能。我做了一些搜索,除了轮询Chrome的本地计时器构造函数外,找不到超过毫秒精度的计数器。

我还需要以“跨平台和跨浏览器”的方式实现它,因此任何解决方案都需要在大多数配置上实现。

谢谢

/edit:状态更新:我可以排除Javascript、Silverlight和Flash。。但是Java小程序呢?用一个可以达到.1毫秒的精度吗?

最佳回答

在这个问题上付出了更多的努力之后,我得出结论:Java小程序(其中System.nanoTime()可用,这给了我足够的精度)是目前最好的选择。

兼容性并不理想(至少与javascript一样),但大多数配置已经支持它们,并且每个常见的配置至少都可以支持它们,只需简单下载即可。

问题回答

不,您将无法在浏览器之间以一致的方式获得接近毫秒的精度。

John Resig写了一篇关于该主题的良好总结。它写于2008年,但总体结论应该仍然有效。





相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签