Using Scripted Links             

As soon as you decide to use a Java menu system or linking applet on your site, you give up some of the flexibility that a plain HTML link allows. And one of the most useful options a standard <A HREF> has to offer is the ability to call JavaScript functions on the page.

Up until now you've been forced to compromise. But the addition of Scripted Links support to our applets finally gives designers the flexibility of HTML and JavaScript with the style and impact of Cool Focus Java design. And this powerful feature could hardly be easier to use!

First... A Few Limitations
There are four limitations to this feature. First, if the applet has not been registered, JavaScript calls can only be made when the applet is running on your local system. Second, this feature will not work in Internet Explorer versions earlier than 4.0. Third, Netscape browsers cannot talk to a Cool Focus 'Satellite' at the same time as talking JavaScript. Thus, once you add the MAYSCRIPT attribute to your <APPLET> tag (see below), you will be unable to work with Satellites from that applet. Finally, Netscape Communications forgot to include Java-to-JavaScript connectivity in v4.60, so Java links pointing to JavaScript methods will do nothing when clicked in this version of the once-respected browser.

Talking JavaScript
Scripted Links let you replace the contents of any URL parameters in Cool Focus applets with calls to JavaScript functions. Since that JavaScript function can do whatever you want it to do, you're not losing the opportunity to make a link by using that parameter in this way: just include a call to window.open(url, framename) somewhere within that function to make the link, together with any other scripting that you need to include. Note that you can't include both a URL and a JavaScript function call in a single parameter.

There are two steps involved in making a Cool Focus applet talk JavaScript.

1. The MAYSCRIPT Attribute
First, add the MAYSCRIPT attribute to your <APPLET> tag. This is a self-contained attribute that has no = sign and no value setting, and it can be placed in any position within that tag. So the result may look like this:

<APPLET CODE="ACoolFocusApplet.class" WIDTH=200 HEIGHT=348 MAYSCRIPT ARCHIVE="ACoolFocusApplet.jar">

This attribute is fundamental to the use of this feature, since it creates the vital interface between the applet and the contents of the surrounding web page.

2. The Function Call
Add a URL parameter for the menu entry that should call a JavaScript function. (Details of how to do this for the applet you're using are given in The Parameters Explained.) The value for this parameter will be the word JavaScript: (including the colon) followed by the function to be run. For example, if you have a function called MyFunction() that you want URL3 to call, your parameter would look like this:

<param name=URL3 value="JavaScript:MyFunction()">

The word 'javascript' is not case sensitive, but it must be spelled correctly and be followed by a colon. There must be no spaces between 'javascript', the colon, and the function name.

Real JavaScript
Because we're dealing with real JavaScript here, you can pass parameters in your function calls. For example, you may want to pass the text of the current menu entry or button (as a string) and its number (as an integer) to the function, so your parameter might be:

<param name=URL3 value="JavaScript:MyFunction('Home Page', 3)">

Note that wherever quote-marks are required in the expression, single quotes must be used.

In addition to defining your own functions, you can call predefined JavaScript functions like the following:

Dynamically create a page using document.write:
javascript:document.write('Why did you click that then?')

History-linked Back and Forward buttons:
javascript:history.back() and javascript:history.forward()

Close the current browser window:
javascript:window.close()

Display an alert message (perhaps not too useful in itself):
javascript:alert('Thank you for clicking that entry!')