English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
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.
window.alert(msg)
alert("Hello world!");Test and See‹/›
All browsers fully support the alert() method:
Method | |||||
alert() | Yes | Yes | Yes | Yes | Yes |
Parameter | Description |
---|---|
msg | (Optional) The string to be displayed in the alert dialog, or the object to be converted to a string and displayed |
Return Value: | None |
---|
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:
Window (Window) Reference:confirm() Method
Window (Window) Reference:hint() Method