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 an 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. Works for the main and secondary windows like pop-ups.
procedure OnStartMainWindow;When the main window is going to be displayed (just before the homepage is shown).
procedure OnCloseWindow (WindowName: String);When a window is closed by the user.
function OnWindowCloseQuery (WindowName: String): Boolean;When a 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.
function OnInvalidPasswordAtStartup: Boolean;Occurs when an invalid global password is provided at startup. Note: set to True if you want the publication NOT to display an error message and exit.
function OnExpiredPublication: Boolean;Occurs when the global expiration date is reached. Note: set to True if you want the publication NOT to display an error message and exit.
procedure OnTrayIconClick;The user clicks on the tray icon.
procedure OnTrayIconDblClick;The user double-clicks on the tray icon.
procedure OnPDFDisplay(PDFPath: String);This event is called when the built-in PDF viewer loads and displays the PDF whose path is given by PDFPath. It lets you pass commands thanks to the PDFViewerCommand function.
function OnKeyNotValidated: Boolean;Occurs when the validation of a registration key failed. Set to True if you want the publication to exit.
function OnKeyValidation: Boolean;Lets you decide whether validation of the registration key should be performed at startup or not. Set Result to True if you want the publication to validate, False otherwise.
function OnModifySearchRequest(Request: String): String;Called when a full search is initiated. “request” contains the exact user query. You can change the user query and return it with Result. For example, you want to find all product codes that begin with “DWT-DW”. The search will work if you enter “DWT-DW”. With the OnModifySearchRequest event, you can add the “” parameter automatically to the search query with one line code: Result := Request + "*";

The following events are available only in an 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 identifier 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 an HTML page sends an 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 an 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. 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 identifier 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 an 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


Copyright G.D.G. Software 2018. All rights reserved