Assignment 21: A Possible Answer
You actually have to hit cancel to be reading this. Here's how I did it.
In the HEAD commands, I put this:
<SCRIPT LANGUAGE="javascript">
function wannago()
{
if (confirm("Are you sure you want to enter HTML Goodies?") )
{
parent.location='http://www.htmlgoodies.com';
alert("Good choice");
}
else
{
alert("Then you'll stay right here");
defaultStatus='Chicken!';
}
}
</SCRIPT>
|
...and the <BODY> command looks like this:
<BODY BGCOLOR="ffffcc" onLoad="wannago()">
The process was actually quite simple:
- The function was created by copying and pasting the script between the <HEAD> commands, adding the function statement, then surrounding the entire code with two more fancy parentheses. It makes for a lot of the little buggers, but they're all needed.
- The command "defaultStatus='Chicken!';" was added in the "else" section to get the text in the status bar.
- The function is triggered by an onLoad Event Handler in the BODY command.
- If you wanted to get fancy and have the page open in a new window, you only had to change out two words. Exchange "parent.location" with "window.open" and you're done.
Did You Get It?
Back to the Index Page