Zuker
Zuker

Reputation: 456

Only allow user to close a JavaScript alert after 10 seconds

Is it possible to prevent a user from closing a JavaScript alert until 10 seconds have passed?

I trigger an alert, and then user must wait "x" seconds to be able to close it.

Upvotes: 0

Views: 762

Answers (3)

Jonathan M
Jonathan M

Reputation: 17451

Here's a better way:

You'll want to avoid alert, since you have no control over the dialog box with it. Instead, try a modal dialog like ThickBox. It's a jQuery plugin (so you'll need the jQuery library). Look at the "inline" example on this page: (click "demo" then "Show hidden modal content" link)

http://jquery.com/demo/thickbox/#sectiond-1

Initially, hide the OK button and use a setTimeout() to then show it after 10 seconds.

Upvotes: 2

HellaMad
HellaMad

Reputation: 5374

Not possible. If it were, it could be abused easily.

Upvotes: 0

Ruan Mendes
Ruan Mendes

Reputation: 92314

Not using alert, You have to create your own (almost) modal dialog using JS and HTML with an OK button that is disabled, then use setTimeout to enable it after ten seconds

Upvotes: 1

Related Questions