0

I need to hide one javascript alert message after 10 seconds.is it possible to achieve this.

partha
  • 11
  • 1
  • 2
  • No you cannot.Alert or a Confirm messagebox halts the execution of the script altogether and no part of your code can run afterwards(remember Javascript is single threaded) to close.Also there is no inbuilt API that allows you to close the native popup without the user interaction. – Prabhu Murthy Aug 11 '14 at 05:05

3 Answers3

1

No, you can't hide it programmatically. You can use customised UI components, like jQuery UI dialog to emulate alert and hide it:

$("#dialog").dialog();//create customized alert
//do something
setTimeout(function () {
    $("#dialog").dialog('close');//hide it after 10 seconds
}, 10000)'
Alex
  • 11,115
  • 12
  • 51
  • 64
0

No, It's not possible in plain old javascript alert boxes..

But yes, you can definitely use modern custom alert dialog boxes to do so.

Two of the most favourites are as follows :

Bootbox : http://bootboxjs.com/

Malsup Block UI : http://malsup.com/jquery/block/

Manish Kr. Shukla
  • 4,447
  • 1
  • 20
  • 35
0

This is not possible with a javascript alert().

To get similar functionality, you could instead show a hidden <div> which you can hide after a delay.

To do this, use something like

document.getElementById("myDIV").style.display="block";
setTimeout(function(){
    document.getElementById("myDIV").style.display="none";
}, 10000);

which would show the div 'myDIV', wait 10 seconds (10000ms), then hide the div. You would also need to set 'myDIV' to display none in your css.