简体   繁体   中英

How can I cancel an alert box?

I can display an alert box as follows: alert('Please wait 5 seconds'); .

Is there a way to remove this alert box after 5 seconds if the user has not clicked "OK" by that time using JavaScript?

No, you cannot do that.

As an alternative you could create some sort of modal window right in your UI.

When a native JS alert dialog is fired the browser stops everytihng, until the user clicks "OK", this goes for the confirm() funciton as well.

I recommend using jQuery's UI dialog component: http://jqueryui.com/demos/dialog/

Highly configuratble, modal, non modal, size, and of course for your use... timed interval. Heck you can even ad a nifty timer that counts down!

As far as I know there is no way to do this using the browsers alert window. JavaScript cannot be executed when an alert box is "Alerting". However you could use a UI element with a close() method, as the displaying of such an element would not stop the browser from executing your JavaScript.

The alert can not be removed, what you can do is to make a custom alert using jquery. With jquery, you can customize your alert theme and decide how its going to be removed with a simple command like fadeOut();

This may not help the poster at all but I bet some finders readers will get through fire and flames out with this : reload the script the alert box is displayed from.

To do this you should add an invisible frame from which the alert box is fired, and reload that frame without affecting your dear front page... Not even sure if that works I'll go try and come back to this...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM