You are here: Reference > JavaScript > client-side > dialog > methods > alert (window)

alert method (window)

Browser support:
Displays an alert window with the specified message and an OK button.
This method makes it possible to notify the user about important information. Script execution does not continue until the alert method returns (the user presses the OK button or closes the alert window).
  • To display a confirmation dialog, use the confirm method.
  • To display a prompt dialog, use the prompt method.
Note: when the alert method is invoked for an object, it displays the string returned by the toString method of the object.

Syntax:

object.alert ([message]);
You can find the related objects in the Supported by objects section below.

Parameters:

message
Optional. String that specifies the text for the message in the dialog box. Default is an empty string. This parameter is required in Firefox.

Return value:

This method has no return value.

Example HTML code 1:

This example illustrates the use of the alert method.
<head>
    <script type="text/javascript">
        function Notify () {
            alert ("The operation was successful!");
        }
   </script>
</head>
<body>
    <button onclick="Notify ()">Create an alert window</button>
</body>
Did you find this example helpful? yes no

Supported by objects:

Related pages:

External links:

User Contributed Comments

Post Content

Post Content