Navigation: For Developers >

HTML Executable JavaScript API





In this topic, we explore the powerful JavaScript Internal API provided by HTML Executable for your ebooks and applications. This API allows you to control your applications using JavaScript, offering seamless integration with your HTML pages.


HTML Executable features its own script language called HEScript, enabling you to manage your applications effectively. In addition to HEScript, you can harness the power of JavaScript to control your application through the htmlexe object.


To close your application programmatically, utilize the following JavaScript snippet:




⚠️ Warning: The JavaScript extension employs asynchronous callbacks. Consequently, the functions listed below do not return results directly. The actual result is obtained through a callback mechanism, as explained below.


List of htmlexe Methods


Method Name


Description and Comments


`procedure htmlexe.CloseCurrentWindow();`

Closes the current window, which may prompt end users.


`function htmlexe.GetGlobalVariable(name, defvalue, callback)`

Retrieves the value of a global variable by name. If not found, the defvalue is returned. The result is obtained through the specified callback function. Similar to GetGlobalVar HEScript function.


`procedure htmlexe.SetGlobalVariable(name, value, isstored)`

Sets the value of a global variable with the option to make it persistent. Similar to SetGlobalVar HEScript function.


`function htmlexe.RunHEScriptCom(comline)`

Executes an HEScript function or procedure and returns its result (for functions). This is akin to the hescript:// protocol with the added ability to specify the command line via `comline` and a default value in case the function is not found.


`function htmlexe.RunHEScriptCode(code)`

Compiles and executes HEScript code specified by `code` directly.


`function htmlexe.GetHEScriptCom(comline, callback)`

Executes an HEScript function and retrieves its result. Similar to the hescript:// protocol, but with the ability to specify the command line via `comline`. The result is obtained through the specified callback function.


`procedure htmlexe.GoToPage(url, window);`

Navigates the application to the specified URL in the named window.


`function htmlexe.GetString(name, callback);`

Retrieves a resource string by its name. The result is obtained through the specified callback function. Useful for localization.




Calling an HEScript Function from JavaScript


You can call an HEScript function from JavaScript using this function:


function executecom(sname) {
    return htmlexe.RunHEScriptCom(sname);


For example, to call the HEScript procedure `UserMain.Procedure1`, use either of the following:




Similar to the hescript:// protocol, parameters can be passed like this:




Displaying a Resource String in HTML


To display a resource string in an HTML page, use the following code:


<script language="JavaScript">
function DemoCallback(content) {
  document.getElementById('demo').outerHTML = '<p>' + content + '</p>'; 
<div id="demo"></div>  
<script language="JavaScript">
htmlexe.GetString("[Name]", DemoCallback);


Replace `[Name]` with the desired resource string's name.


Retrieving the Value of a Global Variable


<script language="JavaScript">
function DemoCallback(content) {
<script language="JavaScript">
htmlexe.GetGlobalVariable('[Name]', DemoCallback);


Replace `[Name]` with the name of the global variable. Refer to the list of pre-defined global variables for more information.


Calling an HEScript String Function and Retrieving Its Result


JavaScript code:


<script language="javascript">
function DemoCallback(content) {
htmlexe.GetHEScriptCom('usermain.getit|password1', DemoCallback);


This code calls the HEScript string function defined in UserMain:


function getit(what: String): String;
    Result := MD5OfAString(what);


Closing the Application with JavaScript and RunHEScriptCode


To close the application programmatically, use:




For more information, explore the following topics:


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?

Special Targets for External Links

Application Global Variables

Publication Command Line Arguments

Command Line - Directives

Environment Options