Now this is a problem that does not help me change the confirmation dialog for the site, as was done with alert ();
It is right. It is not possible to reproduce the synchronous nature of alert / confirm / prompt functions in native JavaScript. There is a non-standard showModalDialog method that can execute it with a separate pop-up document, but it is not supported by all browsers and is generally considered highly undesirable.
Thus, the plug-in-replacement strategy will not work. You will have to change all the places you called these methods in the rest of the script.
The usual template is to do this with built-in anonymous functions to save local variables using closures, for example. replace:
function buttonclick() { var id= this.id; if (confirm('Are you sure you want to frob '+id+'?')) frob(id); wipe(id); }
from:
function buttonclick() { var id= this.id; myConfirm('Are you sure you want to frob '+id+'?', function(confirmed) { if (confirmed) frob(id); wipe(id); }); }
If you need to save this , you will need to look for another nested closure or .bind function to do this. If you have your confirm call in a loop, the situation becomes much more complicated.
Obviously, you also need to ensure that the critical global state does not change while the confirmation window is inserted. Usually this risk is minimized by unloading the rest of the page with an overlay to stop clicks from passing. However, if you have timeouts, they can still shoot.
bobince
source share