Hello and welcome to the Webmasters Forums!. This is the best place to get webmasters resources for free. Get $2 for free today, read more - Make your payment today. Download premium and professional templates for free. Get free web hosting without ads, read more. You can get lot more by simply join with this forum. To gain full access to the forums you must sign up for a free account.
Posts: 995
Group: Forum Team
Joined: Sep 2006
Status: Online
Make money from now. You can make money just for posting on this forum. Every discussions on this community gives you more money. $2 minimum payout. So get your payment today, SignIn with this forum.
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>
Yes! Now you can drive your friends insane with a bunch of fake links! Here's what all the commands are doing:
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.
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.
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>
<TITLE>Cool JavaScripts</TITLE>
<SCRIPT language="JavaScript">
<!-- hide from old browsers
alert('Welcome to my Web Site!');
//-->
</SCRIPT>
</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:
<SCRIPT language="JavaScript">
This tag lets the browser know you are using JavaScript commands here.
<!-- hide script from old browsers
This makes sure older browsers don't display your script as text on the page.
alert('Welcome to my Web Site!');
This is your alert. Put your mesage inside the single quotes. Notice the semicolon at the end, this is what separates JavaScript commands.