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:
1. onMouseover=" "
This tells the browser to execute the command or function inside the double quote marks when the user moves their mouse over the link.
2. alert('Hey! I said not to try clicking this link!')
Instructs the browser to display the text inside the single quotes in an alert window.
<!-- hide from old browsers
alert('Welcome to my Web Site!');
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:
2. <!-- hide script from old browsers
This makes sure older browsers don't display your script as text on the page.
3. alert('Welcome to my Web Site!');
Stops hiding the script from old browsers.
Do you want to try it out? Click on the link to see the alert before the new page.
So, do you want to get carried away? Place several of these alerts inside the SCRIPT tag, following each with a semicolon. The viewer will have to say "OK" to every alert before the page will begin loading. Try it out yourself and see if you go insane. Click the link below!
Want the code that did this? Here you go!
alert('Please Sign My Guestbook, NOW!');
alert('I mean it, NOW!!!');
alert('Did I mention I had a guestbook? Well SIGN IT!');
alert('Oh, remember....THE GUESTBOOK! O.K.?!!');
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.
<INPUT type="button" value="Click here to see what I think of YOU!"
onClick="alert('You are the greatest person I have ever met!')">
Give it a try. You'll be glad you did....I think.....
Well, that wraps up this section. Let's Go on to
Variables and Functions.
||By: John Pollock||