User Scripting

Applies to HTML Viewer, IE Browser publications.

HEScript is the scripting language of HTML Executable used to customize the behavior of your publications and ebooks. Scripts are compiled during the compilation into bytecode for faster execution at runtime (contrary to JavaScript). That’s why scripts are separated from HTML pages and stored in a script manager. You can manage scripts using this User Scripting page.

You may use JavaScript too in IE publications. JavaScript and HEScript can be easily combined.

Introduction to scripting with HEScript

img

Each script that will be compiled into the script collection of the publication is listed. You have the name of the script and an optional description. Each script must have a unique name (similar to a namespace).

Adding and managing scripts

To add a new script, press Add and the following window will appear:

Add script

You first give a name to the script. Space and special characters are not allowed (only alphanumeric ones). The maximum length for a script name is 255 characters.

Then you can choose a template for your script. A script template is actually a blank script with some pre-defined procedures or functions called events. When a script is, for example, associated with an HTML page, the publication will call a pre-defined function when its related event occurs (when an HTML object is clicked for instance).

More information about pre-defined scripts, templates, UserMain and Macros

There are several templates available:

  • script for an HTML page: the new script is intended to work with an HTML page. You can then associate this script to its HTML page in the File Manager -> File Properties -> Associated Script.

  • script for a security profile: this script is designed to be associated with a security profile. For instance, it may be used to create some conditions (result of a Boolean function) for the security profile.

  • script for a custom HTML dialog: this script should control the associated custom HTML dialog box. The Favorite manager and the About box in publications are examples. They are actually custom HTML dialog boxes.

Finally, you can give an optional description to your script. However, it is not used by HTML Executable at all.

Press OK to start your new script; the script editor will then be displayed to edit your new script:

img

You are not forced to edit your script right now. Just click Save to finish the script editing: you can see that the new script then appears in the script list.

More information about the script editor

To edit a given script, select it in the list and press Edit. You can also double-click on it. The script editor will be displayed.

To remove a script, select it in the list and press Remove. Note that you can’t remove the UserMain script.

To import/export a script, select it in the list and press XML Tools. Then select Import/Export and you will be prompted to enter the filename for the XML file. Scripts are stored in the XML format so you can edit them with any XML editor (or even Notepad if you wish). When you import a script back, the script editor is displayed: press Save to import the script. Note that an imported script is automatically syntax-checked (this prevents possible script errors during the compilation of the publication).

Notes

  1. By default HTML Executable automatically adds a “UserMain” script when a project is created. This script is designed for your own use and contains some pre-defined global events related to the ebook.
  2. Scripts may be associated with HTML pages, conditions of security profiles, etc… You can also call HEScript functions from your HTML code (links) and even from JavaScript. More information is available here.
  3. Scripts are stored inside the project file. No external file is required.

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