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:

 

htmlexe.RunHEScriptCode('ExitPublication;');

 

⚠️ 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

Prototype

Description and Comments

CloseCurrentWindow

`procedure htmlexe.CloseCurrentWindow();`

Closes the current window, which may prompt end users.

GetGlobalVariable

`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.

SetGlobalVariable

`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.

RunHEScriptCom

`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.

RunHEScriptCode

`function htmlexe.RunHEScriptCode(code)`

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

GetHEScriptCom

`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.

GoToPage

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

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

GetString

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

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

 

Examples

 

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:

 

javascript:executecom("UserMain.Procedure1")
 
javascript:htmlexe.RunHEScriptCom("UserMain.Procedure1")

 

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

 

javascript:htmlexe.RunHEScriptCom("UserMain.Procedure1|Param1|Param2")

 

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>'; 
 }    
</script>
 
<div id="demo"></div>  
 
<script language="JavaScript">
htmlexe.GetString("[Name]", DemoCallback);
</script>

 

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

 

Retrieving the Value of a Global Variable

 

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

 

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) {
    alert(content); 
}
 
htmlexe.GetHEScriptCom('usermain.getit|password1', DemoCallback);
 
</script>

 

This code calls the HEScript string function defined in UserMain:

 

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

 

Closing the Application with JavaScript and RunHEScriptCode

 

To close the application programmatically, use:

 

htmlexe.RunHEScriptCode('ExitPublication;');

 

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