HTML DOM Window alert() Method Last Updated : 22 Aug, 2024 Comments Improve Suggest changes Like Article Like Report 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.Syntaxalert(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. html <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Document</title> </head> <body> <h1 style="color: green;"> GeeksforGeeks </h1> <p> For displaying the alert message, double click the "Show Alert Message" button: </p> <button ondblclick="myalert()"> Show Alert Message </button> <script> function myalert() { alert("Welcome to GeeksforGeeks.\n " + "It is the best portal for computer" + "science enthusiasts!"); } </script> </body> </html> Output:Example: Alert the hostname of the current URLIn 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. HTML <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Alert Hostname Example</title> </head> <body style="text-align: center;"> <h1 style="color: green;"> Geeks </h1> <p> To see the hostname of the current URL, click the "Show Hostname" button: </p> <button onclick="showHostname()"> Show Hostname </button> <script> function showHostname() { let currentURL = window.location.hostname; alert("The hostname of the current URL is: " + currentURL); } </script> </body> </html> Output:Supported Browsers: Google ChromeEdge FirefoxOperaSafari Comment More infoAdvertise with us Next Article HTML DOM Window alert() Method S Shubrodeep Banerjee Follow Improve Article Tags : Web Technologies HTML HTML-Methods Similar Reads HTML DOM Dialog show() Method The DOM Dialog show() method is used to show the dialog. The Dialog element is accessed by getElementById(). It is used in HTML5. While using this method, the user can interact with other elements on the page. Syntax: dialogObject.show() Example: This example shows the working of Dialog show() Metho 1 min read HTML Window createPopup() Method The HTML createPopup() method was used to create custom popup windows in Internet Explorer but is now obsolete and not supported by modern browsers due to security concerns.Syntax:window.createPopup()Example: In this example we use the createPopup() method to generate a pop-up window with custom con 2 min read HTML DOM write() Method The write() method in HTML is used to write some content or JavaScript code in a Document. This method is mostly used for testing purposes. It is used to delete all the content from the HTML document and inserts the new content. It is also used to give additional text to an output that is opened by 2 min read HTML DOM open() Method The DOM Open() method in HTML is the combination of the following three steps: Opens an output stream to collect the output.Collects output from the document.write() or document.writeln() methods.Runs the document.close to display the output written to the output stream. Syntax: document.open( MIMEt 2 min read HTML | DOM Window closed Property The Window closed property in HTML DOM is used to return a value that indicates whether the referred window is closed or not. Syntax: window.close() Return Value: A Boolean value, true if window is closed otherwise false. Example: HTML <!DOCTYPE html> <html> <head> <title> HT 1 min read Like