I would like to replace the Javascript confirm() function to allow custom buttons instead of Yes/Cancel. I tried searching but all the solutions are event driven such as jquery dialog(where the code does not wait for a response but it is event driven). Does anyone know of a non-event driven solution. It must work in Safari as well as IE (so no vbscript).
Here is sample code in many parts of my system. This is old code and was not designed with event driven windows in mind. I am trying to avoid a rewrite.
**
// Wait for users response
if (result>2000) {
if (confirm("Are you sure this is right?")){
... do stuff
}
}
... continue with other stuff
... lots of other code.
if (confirm("Did you double check your numbers?")){
... do more stuff
} else {
... do something
}
**
Like the others have said, this isn’t possible.
confirmis a blocking function – no more script is executed until the user has dismissed the dialog – and you can’t simulate that with other methods of Javascript.A better solution would be to structure your code for asynchronous execution. This is almost always a better idea — firstly, it lets you decide how your dialogs should look, what buttons there are, etc; and secondly, it doesn’t block the user. They might have the important information they need to double-check open in another tab, or elsewhere on the page. With
confirmthey’d have to answer your question before being able to get to either of these places.Here’s a snippet of what the code might look like. There’s a lot of blank bits here, but it might put you on the right track:
You’ll see here that there are two functions defined, but none actually get executed. The
displayConfirmfunction would have to construct a dialog box (in whichever way) and then create buttons, using those functions as the click handlers (or at least, calling them from the click handler).