Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript alert box with timer

Tags:

javascript

I want to display the alert box but for a certain interval. Is it possible in JavaScript?

like image 246
RKh Avatar asked Dec 26 '09 08:12

RKh


People also ask

How to set time for alert box in JavaScript?

If you want an alert to appear after a certain about time, you can use this code: setTimeout(function() { alert("my message"); }, time); If you want an alert to appear and disappear after a specified interval has passed, then you're out of luck.

Can we customize alert box in JavaScript?

The standard alert box in JavaScript does not provide the option to apply CSS. To style your alert box, you need to create a custom one first. The custom alert box will be created using jQuery and styles will be applied to CSS.

How do you alert in JavaScript?

One useful function that's native to JavaScript is the alert() function. This function will display text in a dialog box that pops up on the screen. Before this function can work, we must first call the showAlert() function. JavaScript functions are called in response to events.

What is an alert box in JavaScript?

Alert Box. An alert box is often used if you want to make sure information comes through to the user. When an alert box pops up, the user will have to click "OK" to proceed.


1 Answers

If you want an alert to appear after a certain about time, you can use this code:

setTimeout(function() { alert("my message"); }, time); 

If you want an alert to appear and disappear after a specified interval has passed, then you're out of luck. When an alert has fired, the browser stops processing the javascript code until the user clicks "ok". This happens again when a confirm or prompt is shown.

If you want the appear/disappear behavior, then I would recommend using something like jQueryUI's dialog widget. Here's a quick example on how you might use it to achieve that behavior.

var dialog = $(foo).dialog('open'); setTimeout(function() { dialog.dialog('close'); }, time); 
like image 181
Xavi Avatar answered Oct 11 '22 18:10

Xavi