I'm trying to override the standard confirm()
method in Javascript (make a nice UI and stuff). I've read a 100 posts that it "can't be done", but I don't want to give up until I have given it a fair shot. :)
So, the real problem is of course that the confirm()
method must block all javascript execution until the user selects an option. So, what are the methods in Javascript that have blocking behavior? I've been able to come up with 5:
alert()
- does not suit me, because it displays an unwanted UI of its own;confirm()
- the same problem asalert()
;- infinite loop - even modern browsers will eat away CPU like crazy and display a "stop javascript?" prompt after a few seconds;
XmlHttpRequest
in synchronous mode - sort of, but it involves server...showModalDialog()
- nice, but I need a specific design, plus there are some browser compatibility requirements...
The best approach I have so far is to create an <iframe>
with the prompt (which then gets its own javascript execution thread) and block with XmlHttpRequest
until the user has selected an option in the <iframe>
. Unfortunately this involves passing the result forth and back between the server, and I'd like to make this 100% client-side. Also, it ties up a server thread while the dialog is opened, and there might be some browser-specific ajax-timeouts that apply.
Can anyone think of any other Javascript methods that block execution which might be (ab)used to achieve the desired effect?