English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Window alert() method

JavaScript Window Object

alert()The method displays a warning dialog containing warning information and a confirmation button.

In addition to message confirmations, warning dialogs are used for messages that do not require any response from the user.

Dialog is a modal window-Before the dialog is closed, they prevent users from accessing the rest of the program interface. Therefore, you should not overuse any functions that create dialogs.

Syntax:

window.alert(msg)
alert("Hello world!");
Test and See‹/›

Browser Compatibility

All browsers fully support the alert() method:

Method
alert()YesYesYesYesYes

Parameter Value

ParameterDescription
msg(Optional) The string to be displayed in the alert dialog, or the object to be converted to a string and displayed

Technical Details

Return Value:None

More Examples

Alert Box Number:

alert(500);
Test and See‹/›

Alert box with a string and a number:

alert("The number is: " + 500);
Test and See‹/›

Alert box with a newline character:

alert("Hello\nHow are you?");
Test and See‹/›

Display the entire URL in the alert box:

alert(location.href);
Test and See‹/›

This example demonstrates the different types of dialog boxes supported by JavaScript:

Click the button below to display different dialog boxes:


Related References

Window (Window) Reference:confirm() Method

Window (Window) Reference:hint() Method

JavaScript Window Object