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.
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.
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.
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.
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.
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/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With