I want to display the alert box but for a certain interval. Is it possible in JavaScript?
setTimeout( function ( ) { alert( "moo" ); }, 10000 ); //displays msg in 10 seconds
If you want an alert to appear after a certain about time use this code:
setTimeout(function() { alert("my message"); }, time);
If you want an alter to appear and disappear after a specified interval has passed, then I you're out of luck. When an alert is fired the browser stops processing javascript code until the user clicks "ok". The same happens when a confirm or prompt is shown.
If you want the appear/disappear behavior, then I recommend using something like jQueryUI's dialog widget. Here's a quick example on how you might use it to achieve this behavior.
var dialog = $(foo).dialog('open');
setTimeout(function() { dialog.dialog('close'); }, time);
In short, the answer is no. Once you show an alert, confirm, or prompt the script no longer has control until the user returns control by clicking one of the buttons.
To do what you want, you will want to use DOM elements like a div and show, then hide it after a specified time. If you need to be modal (takes over the page, allowing no further action) you will have to do additional work.
You could of course use one of the many "dialog" libraries out there. One that comes to mind right away is the jQuery UI Dialog widget