How can I create a popup message window that will close itself after 'n' seconds?

Jorge Jordão

None of the predefined dialogs (alert, confirm, prompt) allow you to do that.

However, you can create your custom dialog window with window.open, and using setTimeout(function, msecs) you can close it after a specified time.


MyDialog.html (HTML content for the dialog window)

    <TITLE>This is my custom dialog</TITLE>
    <FONT FACE="Arial" SIZE="2">
      This is my custom dialog message</FONT>
      <INPUT TYPE="button" VALUE="    OK    "  

Test.html (page that opens a dialog and closes it after a specified time)

    <SCRIPT LANGUAGE="JavaScript">
      function closeDialog() {
      var dialog = window.open("custom2.html","mywindow",
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



About | Sitemap | Contact
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.