VOOZH about

URL: https://www.geeksforgeeks.org/html/html-dom-window-alert-method/

⇱ HTML DOM Window alert() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

HTML DOM Window alert() Method

Last Updated : 11 Jul, 2025

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.

Syntax

alert(message);

Parameter:

Message: It is the message that is needed to show in the alert box and it's optional.

Example: Display an alert box by double-clicking a button. 

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:

👁 Image

Example: Alert the hostname of the current URL

In 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:

👁 jiu

Supported Browsers:

Comment
Article Tags: