Navigation: For Developers >

Extend Functionality with HEScript





🎯 Introduction to Scripting with HEScript - Enhancing Functionality


Dive into the dynamic world of HTML Executable ebooks and publications! These creations are not just static pages - they are powered by scripts and feature a built-in script engine. Each publication is governed by a suite of scripts, generated and compiled into p-code by HTML Executable. When a publication is launched, it shows an interactive web browser-like environment where your end users can explore your HTML pages and interact with your content.


This dynamic nature allows you to extend the functionality of your publications by writing and invoking your own script functions. This powerful feature opens up a world of possibilities, enabling you to customize your publications to your heart's content.


📝 Note: You don't need to delve into scripting to use HTML Executable and compile publications. Scripting is an advanced feature designed for those who wish to exercise full control over their publications.


📚 Unveiling HEScript - The Script Language


✅ The scripting language employed by HTML Executable is known as HEScript. It's built on the Object Pascal language syntax (akin to Embarcadero® Delphi and FreePascal) with a few minor modifications.


Unlike JavaScript, HEScript functions cannot be written directly into HTML pages. This is because HEScript scripts need to be compiled into pseudo-code first. Therefore, you'll need to use the User Script Manager to write and manage your scripts.



✅ Each script that will be compiled into the publication's script collection is listed. You'll see the name of the script along with an optional description. Each script must have a unique name (similar to a namespace).


Here's a simple script example:


 // UserMain
 // This script contains special functions related to some of the events triggered by the publication.
 //You can then optionally add new commands.
    function OnBeforeNavigate(NewURL, TargetFrame: String): Boolean; 
     //Before the publication displays a page. Set Result to True to stop the operation.
    Result := False;
    procedure OnNavigateComplete;
     // When a page has been displayed.


✅ A script file is essentially a collection of procedures or functions. Each script file has a unique name; each procedure/function also has a unique name within its script file, following these rules:


ØOnly alphanumeric characters may be used, no spaces.

ØEach name must be unique within a given script file, but you can have two different script files that contain procedures or functions with the same name.


📌 Key Points to Remember:


ØScript files function like namespaces. When you call a procedure/function or assign it to an event, you'll need to specify the script name, followed by a dot (.), and then the name of the procedure/function, i.e. `[scriptname].[functionprocedurename]`. For example: `UserMain.OnNavigateComplete`

ØEach script is managed by an independent script engine, so you'll need to use global variables to share data between scripts.

ØWhile the use of local variables is possible, it's not recommended for best practices.


Please see these topics too:


Extend Functionality with HEScript

HEScript Script Editor

HEScript Function Reference

Run and Call HEScript From JavaScript And HTML

UserMain Script And Script Templates

Quickly Add HEScript Code

Sample Scripts

How to prompt end users for their name once and store it?

How to password protect pages?

How to call a javascript function from HEScript (toolbar, menubar)?

How to call DLL functions?

How to open an external file

How to open subfolders of a given folder or disk?

How to prompt for a password for closing ebook?

How to run an executable file or app?

How to dynamically modify the Table of Contents?

HTML Executable JavaScript API

Special Targets for External Links

Application Global Variables

Publication Command Line Arguments

Command Line - Directives

Environment Options