Stupid Web Tricks: Add alerts to your site

Add alerts to your site in a snap. Use them to provide extra information to users or just to surprise them with jokes.

You may want to provide visitors to your site with extra information at each turn. Or you may want to surprise them with a clever joke or insight as they move from page to page or use a form button. Whether or not your visitors want to be surprised this way is another question. Regardless, it's a snap to add alerts to your site.

Step One
Paste this code into the <HEAD> of your document:

<SCRIPT language="javascript">
<!— hide javascript

function showAlert () {
alert ("Your alert here");

// done hiding —>

Step Two
Call the showAlert() function from a hyperlink:

<A href="anotherpage.html" onClick="showAlert()">Hyperlinked word or image

When users click that link, they will see a dialog box with your message in it. Closing the box will send them to the URL.

To add an alert to form buttons, just insert the same onClick="showAlert()" to the <INPUT> tag of the button, like so:

<INPUT type=button value="Submit" onClick="showAlert()">

Editor's Picks