| JavaScript Alerts |
| Monday, 14 May 2007 | |
|
Alert! Alert! How to pester your viewers until they can't take any more. Oh yes, and
how to create a JavaScript alert box.
Well, you want to add one of those JavaScript alert boxes that come out of nowhere, don't you? Okay, let's begin with the alert box that just tells the viewer something you want them to know. Here's the alert command: alert('your choice of text') Now, to use it, we'll need to place it inside another command. Let's use one we are familiar with, the onMouseover command. The following script will alert the user that you did not want them trying to click this particular link when they move their mouse over it. <A href="noplace" onMouseover="alert('Hey! I said not to try clicking this link!')"> Don't click this link!</A> Give it a try. Move your mouse over the link below: Yes! Now you can drive your friends insane with a bunch of fake links! Here's what all the commands are doing:
That was nice, but could you make something a little more annoying? Of course! It's called the "alert as soon as you open the page!" alert. Just think, you could tell people stuff before they ever see anything on the page! The trick: placing the alert command inside the <HEAD> </HEAD> tags! You will now get to use the old SCRIPT tags I mentioned a couple of sections ago to set off the JavaScript from the other stuff. Here is the code:
<HEAD> This will display the alert before the page starts loading. When you hit "OK" the page will go on and load normally. Here's the breakdown:
Want the code that did this? Here you go!
<HEAD> So, how about that? Pretty wild, isn't it? You can also use the alert with a button, so that it is not such a surprise. Place the code where you want the button to be on your page. You won't need the SCRIPT tag for this one.
<FORM> Give it a try. You'll be glad you did....I think.....
|