Royal Pinto
Royal Pinto

Reputation: 2911

How to avoid blocking alert box in html

In my HTML page I am displaying alert box many times. After few execution of alert boxes, Browser will ask

"Prevent this page from creating additional dialogs"

How can I avoid this?

Thanks.

Upvotes: 1

Views: 2007

Answers (3)

Isaac Lubow
Isaac Lubow

Reputation: 3573

You can't prevent this: the browser is noticing that the page keeps alerting, and assumes (often, correctly) that there is an infinite loop on the page. Preventing further alerts keeps the page usable (eg you can hit the back button).

If you are using the alerts as a way of communicating important information in the normal course of operation, you might want to consider filling an element on the page with the same info. For (a very non-fancy) example, instead of

alert(x + ' just happened!');

just add a <div id="alert"></div> to the page and do

document.getElementById('alert').innerHTML(x + ' just happened!');

Upvotes: 0

phihag
phihag

Reputation: 288270

Don't use alert for regular user notifications. Instead, use jqueryUI's or your own dialog implementation, or console.log in debugging code.

Bear in mind that modal dialog boxes tend to be user-unfriendly and should only be used in exceptional circumstances (for example, failure of AJAX communication). If you're using modal dialogs in the regular flow of an application (for example if form validation fails), consider an alternative, less intrusive notification, such as adding a red border/background to the form fields in question.

Upvotes: 6

Paul
Paul

Reputation: 141917

You can't. That is basically a security feature added in the browser to prevent sites from having an infinite loop making alert boxes and annoying the user.

Upvotes: 3

Related Questions