Are you able to halt JavaScript execution without locking up the browser? The way you would normally halt execution is to do an infinite while()-loop, but in the case of FireFox, it locks up the browser until the loop has ended.
What's your take on this?
I am trying to override window.confirm() to implement my own dialog using HTML. I am doing this so I don't have to change existing code (it's a pretty big code-base).
I need to be able to halt execution to allow user-input; to in turn return a boolean like the standard confirm function does:
if (confirm("..."))
{
// user pressed "OK"
}
else
{
// user pressed "Cancel"
}
Update
To my knowledge; this cannot be done using setTimeout() or setInterval() since these functions execute the code thats given to them asynchronously.
setTimeoutandsetIntervaldon't execute code asynchronously, they count down and then add the callback function to a queue which is called when the thread becomes idle. The functions themselves then run synchronously.window.setTimeout(andwindow.setInterval) create asynchronous callbacks. Normal program flow continues immediately after calling it and the callback is executed at a later date, depending on the timer length. The fact that JavaScript is single-threaded and the callback, once it has started executing, then blocks other code from executing does not prevent it from having been asynchronous.