Drilldown to Javascript Functions

Corda Server™ lets you drilldown to Javascript* functions as well as Web pages. This section describes how to use Corda Server's Javascript drilldown capabilities:

Note: More information about Javascript functions mentioned throughout this section is available in a Javascript manual.

Drilling down to Basic Functions

To drilldown to a Javascript function, use the Javascript:function() syntax when specifying the target URL. For example, the alert() function is a built-in Javascript function that opens a system message box.

Drilldown to a Javascript function using either ITXML or PCScript.

ITXML

To drilldown to a Javascript function with ITXML, specify the Javascript function in the object’s drilldown property. For example:

Function Drilldown with ITXML

cit:map name="AU">

   <cit:layer name="Backyard">

      <cit:default-shape>

         <cit:drilldown url="javascript:alert(‘alert(%_NAME=%_VALUE)’)"/>

      </cit:default-shape>

   </cit:layer>

</cit:map>

PCScript

To drilldown to a Javascript function in PCScript, specify the Javascript function as the drilldown target in the ddEnable method. For example:

graph.ddEnable(1,2,Javascript:alert("hello there"))

This technique works with any Javascript function defined in the Web page. For information about drilling down to Javascript functions with multiple parameters in PCScript (not ITXML), see Multi-Parameter Functions with PCScript below.

Opening a New Window

A common Javascript drilldown task is opening a link in a new window using the predefined window.open() Javascript function. For example:

graph.ddEnable(1-99,1-99,Javascript:void window.open ('http://<server_address>/getgraph/?id=%_VALUE'))

Important: Using void at the beginning of the statement prevents the current Web browser window from browsing to an empty object.

The window.open command also lets you control the new window's size and attributes. For example:

Opening a New Window in Javascript

<cit:bar-graph name="graph">

<cit:graph-settings>

<cit:drilldown url=Javascript:'void window.open(&#x27;http://<server_address>/getgraph/?id=%_VALUE&#x27;,&#x27;WindowName&#x27;,&#x27;directories=no, height=680,width=680,hotkeys=no,menubar=no,location=no,personalbar=no,status=no, toolbar=no,scrollbars=yes&#x27;);' />

</cit:graph-settings>

</cit:bar-graph>

Note: For information about using window.open with multiple parameters in PCScript, see the Multi-Parameter Functions with PCScript section below.

Multi-Parameter Functions with PCScript

Drilling down to a multi-parameter function in Javascript can cause PCScript errors since Corda Server confuses commas in the parameter list for a name delimiter. For example, the following statement results in a PCScript error:

graph.ddEnable(1-99,1-99,Javascript:void window.open( 'http://<server_address>/getgraph/?id=%_VALUE','WindowName'))

To avoid this, change Corda Server's delimiter with the main.paramDelimiter command. For example:

main.paramdelimiter(|)graph.ddEnable(1-99|1-99 |Javascript:void window.open( 'http://<server_address>/getgraph/?id=%_VALUE', 'WindowName'))main.paramdelimiter(,)

Note: Use this same technique to avoid problems using a semi-colon to delimit multi-function calls in a Javascript drilldown string, but use the main.itemDelimiter command.

Encoding Issues with Extended Characters

By default, Corda Builder™ URL-encodes all drilldown effects. In other words, drilldown strings are encoded in such a manner that browsers are able to properly interpret the intended drilldown destination.

Unfortunately, this creates a problem when the intended target of the drilldown effect is a Javascript function instead of a URL. Corda Builder may URL-encode characters that should be Javascript-encoded instead. Because Javascript functions do not recognize URL encoding, characters might display improperly.

This situation is further complicated on occasions when strings in Javascript functions should be URL-encoded because the string is eventually interpreted by a browser as a URL. Because this is often the case, Corda Builder cannot simply attempt to detect whether a drilldown definition is a URL or a Javascript function. By default, anytime a drilldown passes a string containing an extended character (higher than 127 (0x7E)) through a Javascript function, the string is interpreted as a URL.

For those situations when Corda Builder should interpret this type of drilldown string as Javascript, use the %_JS_ENCODE meta tag. This meta tag instructs Corda Builder to Javascript-encode the drilldown effect rather than URL-encode it. Include the %_JS_ENCODE tag at the end of any drilldown definition that needs to be Javascript-encoded. For example, the following drilldown definition doesn't display correctly. Instead of Group ?, you see Group %e2%84%a2.

Javascript:alert("Category: Group ?")

To resolve this, add the %_JS_ENCODE meta tag, as follows:

Javascript:alert("Category: Group ? %_JS_ENCODE")