DOM Window.alert() Method
The alert() method shows a simple message box and waits until the user dismisses it.
Description
The alert() method displays a modal message box with an OK button. It blocks the page, and all scripts, until the user closes it. Browsers style it themselves, may suppress it when it's shown repeatedly, and block it in sandboxed frames.
It's handy for quick debugging, but for real interfaces a <dialog> element or an on-page message gives a better experience. Use console.log() for debugging output.
The message is plain text, so HTML in it is shown literally, and line breaks can be added with \n. Because it pauses all scripts, timers and animations stop while it's open, which can make it misleading when debugging time-sensitive code.
Syntax
alert()
alert(message)Parameters
- messageOptional. The text to show.
Return Value
None (undefined).
Example
Browser Support
The following information will show you the current browser support for the Window.alert() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





