Search code examples
javascriptdom-events

Close a JavaScript Confirm pop up without clicking OK or Cancel buttons


Possible Duplicate:
Javascript close alert box

A confirm box can be opened by, confirm("Sure?"); which opens a confirm pop up with two buttons- OK and Cancel. The pop up closes when either of the two buttons are clicked. How can we close the pop up without clicking the buttons, pragmatically? Can we trigger the event which closes the pop up using JavaScript?


Solution

  • Short answer: No.

    Long answer: The three DOM0 windows of alert, confirm and prompt are modal windows. The browser (or the browser window, depending) freezes when those using one of those input methods and nothing Javascript-wise happens.

    The only thing you can do is to create a popup DIV with your own confirm buttons and give your popup window callback methods on what to do on confirm accept and cancel.

    A setTimeout could be used to auto-close the window after a pause.