Assignment 13 - 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 LANGAUAGE="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 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, and then surrounding the entire code with two more fancy parantheses. It makes for a lot of the litte 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.

Close this window to return to JavaScript Primer #1