Display An Alert Box On Your Web Page

How to display an alert box to users, showing additional information or a simple message.

The alert() statement generates a message box with the message you specify, and an OK button to close the box. The alert box takes the focus away from the current window, and forces the browser to read the message. The user cannot continue viewing your web pages until the box is closed.

The following JavaScript code is to be placed in the body section of your web page, positioned wherever you’d like it to appear:

<button onclick=”myFunction()”>Click here if you don’t know</button>
<script>
function myFunction()
{
alert(“Justin Bieber!!”);
}
</script>

Place the above code between the beginning and ending of the body tag

<html>

<body>

<p>What’s the worst thing that’s ever happened to music?</p>

<button onclick=”myFunction()”>Click here if you don’t know</button>

<script>
function myFunction()
{
alert(“Justin Bieber!!”);
}
</script>

</body>
</html>

 

What’s the worst thing that’s ever happened to music?

Comments

comments

About the author

Freelancer Information Technology.