3

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?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
Phi_1.618
  • 191
  • 1
  • 1
  • 7
  • 1
    You can't because JS execution is blocked as long as the dialog is open. You have to use your own dialog implementation. – Felix Kling Sep 21 '12 at 15:18
  • 2
    See http://stackoverflow.com/questions/463368/javascript-close-alert-box ... this affects alert boxes too as an FYI. – Peter Bratton Sep 21 '12 at 15:20
  • 1
    Also kind of duplicatish: http://stackoverflow.com/questions/10416798/is-it-possible-to-close-confirm-box-after-a-time-interval – Felix Kling Sep 21 '12 at 15:21
  • Yes, you are right. The link you provided with the question is very similar to what I had asked. – Phi_1.618 Sep 21 '12 at 15:29
  • I presume that hitting escape is not an option either? –  Sep 22 '12 at 18:09

3 Answers3

3

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.

Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74
2

No, because that function is blocking the browser. No JavaScript code will run during the time while it is open - not even scheduled timeouts and other event handlers.

See window.confirm on developer.mozilla.org.

For an example of something that acts in a way that you want, see this example of the jQuery UI library.

rsp
  • 107,747
  • 29
  • 201
  • 177
0

You can only achieve this by creating your own Confirmation box using Modal popup and setting the setTimeout() or setInterval() against it. or try this if it helps....http://cool-javascripts.com/effects/jgrowl-to-show-unobtrusive-messages.html

Scorpio
  • 1,151
  • 1
  • 19
  • 37