Alerts
window.alert() instructs the browser to display a dialog with an optional message, and to wait until the user dismisses the dialog.
Under some conditions — for example, when the user switches tabs — the browser may not actually display a dialog, or may not wait for the user to dismiss the dialog.
Browser support
| Feature | Desktop | Mobile | ||||
|---|---|---|---|---|---|---|
| Chrome | Edge | Firefox | Safari | Chrome Android | Safari iOS | |
| 1 | 12 | 1 | 1 | 18 | 1 | |
| window.confirm() instructs the browser to display a dialog with an optional message, and to wait until the user either confirms or cancels the dialog. | 1 | 12 | 1 | 1 | 18 | 1 |
| window.prompt() instructs the browser to display a dialog with an optional message prompting the user to input some text, and to wait until the user either submits the text or cancels the dialog. | 1 | 12 | 1 | 1 | 18 | 1 |
1+Supported (version) Not supported ※Has note Sub-feature descriptions sourced from MDN Web Docs (CC BY-SA 2.5)
Notes 1 item(s)
Implementation note
- Starting with Chrome 46, this method is blocked inside an `<iframe>` unless its sandbox attribute has the value `allow-modals`.
Notes 1 item(s)
Implementation note
- Starting with Chrome Android 46, this method is blocked inside an `<iframe>` unless its sandbox attribute has the value `allow-modals`.
Notes 1 item(s)
Implementation note
- Starting with Chrome 46, this method is blocked inside an `<iframe>` unless its sandbox attribute has the value `allow-modals`.
Notes 1 item(s)
Implementation note
- Starting with Chrome Android 46, this method is blocked inside an `<iframe>` unless its sandbox attribute has the value `allow-modals`.
Notes 1 item(s)
Implementation note
- Starting with Chrome 46, this method is blocked inside an `<iframe>` unless its sandbox attribute has the value `allow-modals`.
Notes 1 item(s)
Implementation note
- Firefox strips newline characters from the prompt response; see bug 1716229.
Notes 1 item(s)
Implementation note
- Starting with Chrome Android 46, this method is blocked inside an `<iframe>` unless its sandbox attribute has the value `allow-modals`.
Syntax
JAVASCRIPT
window.alert("Hello world!");
alert("Hello world!"); Use cases
-
Using Alerts
window.
Cautions
- May not be supported in older browsers.
Implementation notes
- Some APIs require a secure context (HTTPS) or user activation. Check the requirements before use.