Also see the HTML5
alert() function. All you need to do is pass your message to this function.
alert() function directly into a button element, then use the
onClick event to trigger it. Like this:
onClick event to trigger the alert box. This example, on the other hand, loads automatically as the page is loading. By placing the code by itself (i.e. not within a link/button), this will automatically trigger the alert box as soon as the page is loading.
The alert will popup as the browser renders the code. Therefore, if you place the code within the
<head> tags, your alert box will popup before the HTML elements are displayed. On the other hand, if you call your
alert() function within the
<body> tags, users will be able to see any HTML elements that have been rendered prior to the alert box code.
If you prefer to have the full page visible while the user reads the alert box message, use the
Also see the HTML
<dialog> element, which allows you to do things like, create a dialog box, inspector, window, etc.