![]() |
VOOZH | about |
The alert() method in HTML and JavaScript is used to display an alert box with a specified message. The alert box includes an OK button and is typically used to ensure that the user receives critical information or confirmation before proceeding.
Note: Alert boxes grab your attention and make you read a message and Using too many alerts stops you from doing other things on the webpage until you close them.
alert(message);Message: It is the message that is needed to show in the alert box and it's optional.
In this example the alert() is used to display a message box when the button is double-clicked. The message informs users about GeeksforGeeks. It's a simple way to show notifications or information.
Output:
👁 ImageIn this example we displays the hostname of the current URL when the "Show Hostname" button is clicked. The showHostname() function retrieves the hostname using window.location.hostname and shows it in an alert box.
Output: