Script Templates

Applies to HTML Viewer, IE Browser publications.

When you create a script, you can select a script template which can contain pre-defined events, i.e. functions which are called by the runtime module at appropriate times.

In this topic we will describe these events.

About the UserMain script

The UserMain script is a script that is always created when a new project is started. It contains a lot of global events which allow you to insert special commands.

Event nameDescription
function OnBeforeNavigate (NewURL, TargetFrame: String): Boolean;Triggered just before the publication is going to display a HTML page. Set Result to True to stop the operation. NewURL is the full URL that will be displayed, and TargetFrame the frame where the page is displayed (if any).
procedure OnNavigateComplete (URL: String);When a page has been loaded. URL is the full URL of this page.
function OnPubLoaded: Boolean;When the publication is starting and before the homepage is displayed.
Set Result to True if you want to exit immediately without any warning.
procedure OnPubBeingClosed;When the publication is going to be terminated.
procedure OnStartSearching (what: String);When a full search is initiated. "what" contains the exact user query.
procedure OnDisplayWindow (WindowName: String);When a window (whose name is indicated in WindowName) is displayed.
procedure OnCloseWindow (WindowName: String);When a window is closed by the user.
function OnWindowCloseQuery (WindowName: String): Boolean;When an user wants to close a window. Set Result to False if you do not want the window to close or True if the window can close.
This event is not created by default. You will need to add it manually to the UserMain script of your project if you want to use it.
function OnTimer (TimerName: String): Boolean;This event is triggered by a timer created by StartTimer HEScript function. Occurs when a specified amount of time, determined by StartTimer HEScript function, has passed.
Set the result of this function to True if you want to disable the timer or use StopTimer to disable the timer.
procedure OnPrintPage;When the current page is being printed by the user.

The following events are available only in a HTML Viewer publication:

Event nameDescription
function OnSoundCompleted: Boolean;When the internal media player has finished to play a sound or midi file, this event is triggered. Set the function's result to True if you do not want the media player to continue to play the sound (stop a loop for instance).
function OnFormSubmit (Action, Method: String): Boolean;

When a form is submitted by the user (HTML Viewer only). Set Result to True if you do not want the viewer to handle the form action itself.

In this event, you can use the following script functions: GetFormFieldValue, GetFormContents and SaveFormResultsToFile.

procedure OnObjectClick (OnClick, ID: String);

When an object whose id is ID is clicked and the OnClick HTML parameter is set. Use this event to compensate the lack of JavaScript support in HTML Viewer publications.

procedure OnFlashFSCom (pageURL, command, args: String);When a Macromedia Flash object in a HTML page sends a FSCommand to the browser, this event is triggered. PageURL is the URL of the page that contains the Flash movie, command and args are data sent by the movie to the browser.

This event is useful if you want to use ActionScript in your Flash movies in addition to HEScript.

Events for HTML page scripts:

When you associate a script to a HTML page, some events will be called by the runtime module.

Event nameDescription
procedure OnPageLoaded;When the page has been loaded.
function OnLeavePage (NewURL, TargetFrame: String): Boolean;Triggered just before the publication is going to leave the page. Set Result to True to stop the operation. NewURL is the full URL that will be displayed, and TargetFrame the frame where the new page is displayed (if any).
function OnSoundRequest (SRC: String; Loop, Terminate: Boolean): Boolean;HTML Viewer publication only.

When a sound is going to be played by the internal viewer. Set Result to True to prevent the viewer from playing the sound.

function OnFormSubmit (Action, Method: String): Boolean;HTML Viewer publication only.

When a form is submitted by the user (HTML Viewer only). Set Result to True if you do not want the viewer to handle the form action itself.

In this event, you can use the following script functions: GetFormFieldValue and SaveFormResultsToFile.

procedure OnObjectClick (OnClick, ID: String);HTML Viewer publication only.

When an object whose id is ID is clicked and the OnClick HTML parameter is set. Use this event to compensate the lack of JavaScript support in HTML Viewer publications.

procedure OnPageFlashFSCom (command, args: String);HTML Viewer publication only.

When a Macromedia Flash object in the HTML page sends a FSCommand to the browser, this event is triggered. Command and args are data sent by the movie to the browser.

This event is useful if you want to use ActionScript in your Flash movies in addition to HEScript.

About the Macros script:

This optional script contains some pre-defined macro functions that you can call from your HTML pages like any other functions. This script is actually a collection of useful functions that you may generally need for each publication.

  • See this important topic about how to call HEScript functions from HTML pages, JavaScript, menus, buttons, etc...
     
  • You can customize this macro script file by editing the "defmacro.xml" file in the HTML Executable's main folder: it is possible to insert your own favorite commands.
     
  • Contrary to the UserMain script, this script is not mandatory: you can remove it if you don't call its functions. In the Environment Options, you may also decide not to include this script each time you start a project.

Introduction to Scripting

Using the Script Manager

Script Function Reference