Modern Java
http://www.modernminds.com
J avaScript From Applet

If the Ultimate Button Bar is run in a JavaScript aware browser, the applet can interact with the web page by means of JavaScript function calls.

The ability to access JavaScript from the applet opens many exciting possibilities, such as the capability of controlling Dynamic HTML functions on the web page from buttons created by the applet.

This documentation, which describes how to use the Ultimate Button Bar applet to call JavaScript functions, is divided into the following sections:
R equirements

The primary requirement for calling JavaScript functions from the Ultimate Button Bar is for the browser that is running the applet to be JavaScript aware.

At present, there are only two known browsers that will allow JavaScript and the Ultimate Button Bar to communicate: Microsoft Internet Explorer 4.0 or higher, and Netscape Navigator 4.0 or higher.

The second requirement for calling JavaScript functions is that the MAYSCRIPT applet attribute must be included in the applet tag. For example:


<APPLET CODE="UBBApplet.class"
        MAYSCRIPT ARCHIVE="UBB.jar"
        NAME="UBB" WIDTH="415" HEIGHT="30">
...
<PARAM NAME="UBBdefnFile" VALUE="ButtonBar.txt">
...
</APPLET>

The MAYSCRIPT attribute gives the applet permission to call JavaScript functions on the web page. If you omit the MAYSCRIPT attribute from the applet tag, then the applet will log an error message to the Java log or Java Console whenever a JavaScript function is called from the applet.

C alling Functions

JavaScript functions can be called by the Ultimate Button Bar by specifying a JavaScript function for the UBBjsInit, UBBjsStart, UBBjsStop, UBBjsEnter, UBBjsExit, or UBBinitErr applet parameter, or by specifying a javascript, jsEnter, or jsExit action in an <ACTION> tag.

If a JavaScript function is defined in an <ACTION> tag, then the JavaScript function may optionally be conditioned so that it is only executed when the applet is in a specific JavaScript mode. JavaScript modes are discussed in the JavaScript to Applet documentation.
F unction Format

A JavaScript function is specified for an applet parameter or an <ACTION> (see "Calling Functions" above) using the following format:


"functionName(parameter 1, parameter 2, ... )"

where "functionName" is the name of the JavaScript function to be called, and "parameter 1," "parameter 2," et cetera, are comma separated parameter values that are passed to the function.

NOTE: The applet parameter UBBinitErr is different then the other applet parameters that specify a JavaScript function in that it has a fixed format that does not allow user defined parameters to be passed. See the parameter documentation for further information.

While the Ultimate Button Bar JavaScript function call looks very similar to a standard JavaScript function call, there are some important differences that you must be aware of:
  • The parameter list passed to the function may contain only simple, predefined values. In other words, you cannot reference variables, or specify JavaScript functions in the parameter list.

  • Double quotation marks should not be used in the parameter list as they might confuse the Ultimate Button Bar's tag parser.

    For example:


    The following is not valid:

    <action over
            javascript="btn("This is string 1", 5)"

    The following is valid and will pass the value This is string 1 as the first parameter and the value 5 as the second parameter:

    <action over
            javascript="btn(This is string 1, 5)"

    The following is valid and will pass the value 'This is string 1' as the first parameter (note the two single quotation marks) and the value 5 as the second parameter:

    <action over
            javascript="btn('This is string 1', 5)"

  • Parameters passed to the JavaScript function are delimited by commas. This means that multiple word strings can be passed as a single parameter without the use of quotation marks, but it also means that you cannot place a comma in a multiple word string as the comma will cause the string to be treated as multiple parameters.

    For example:


    The following will pass the value Yes as the first parameter, the value it is as the second parameter, and the value 5 as the third parameter:

    <action over
            javascript="btn(Yes, it is, 5)"

    The following will pass the value 'Yes as the first parameter (note the single quotation mark), the value it is' as the second parameter (note the single quotation mark), and the value 5 as the third parameter:

    <action over
            javascript="btn('Yes, it is', 5)"

    To pass all of the characters between the parenthesis as a single parameter to the JavaScript function, place a "1" (one) in front of the function name (note that the "1" is not a character in the actual function name).

    For example:


    The following will pass the value Yes, it is, 5 as the first and only parameter to the btn function:

    <action over
            javascript="1btn(Yes, it is, 5)"

    The following will pass the value Yes, it is as the first and only parameter to the btn function:

    <action over
            javascript="1btn(Yes, it is)"
Copyright © 1998 by Modern Minds, Inc.