Run and Call HEScript Script Procedure/Function

HEScript scripts have multiple possible uses with:

  • PHP and HTML pages

  • HTML links

  • JavaScript functions

  • global application events.

In this topic, you will learn how to call functions/procedures of HEScript scripts.

You can call HEScript procedures and functions independently via HTML links. You have to use the hescript:// prefix instead of http:// to inform the application that it should execute an HEScript procedure/function. The hescript:// prefix is followed by script name + dot + procedure/function name, i.e. hescript:[scriptname].[functionprocedurename]

Examples: hescript://MyScript.Procedure1 or hescript://UserMain.OnNavigateComplete

In HTML code:

<a href="hescript:MyScript.Procedure1">Click here to execute my first function</a>

For instance, we wrote a small script called "demo1" in the Script Manager which contains the following procedure:

procedure MyFirstDemo;
begin
MessageBox("This is a simple message.", "First Demo", MB_OK+MB_ICONINFORMATION);
end;

Then the following HTML code was put below:

<a href="hescript:demo1.MyFirstDemo">Click here to execute this function</a>

If your procedure/function uses string parameters (only string parameters!), you can pass them using a | separator.

Syntax:
hescript://[scriptname].[functionprocedurename]|param1|param2|.....|paramN

Example:
hescript://MyScript.ProcedureA|test

Warning

Important: please properly encode non-ASCII characters of parameters (ExeOutput for PHP can decode them).

URL encoding replaces unsafe ASCII characters with a % followed by two hexadecimal digits. For instance, spaces in filenames should be replaced by %20. To convert characters online, you will find an application at: http://www.w3schools.com/tags/ref_urlencode.asp

Another Demonstration: We are using a second example. The script procedure in "demo1" is:

procedure MySecondDemo(cond: String);
var
S: String;
begin
S := "first";
if cond="2" then S := "second";
MessageBox("The " + S + " link was clicked", "Second Demo", MB_OK+MB_ICONINFORMATION);
end;

It takes one string parameter.

We use two links where we only change the parameter from "1" to "2":

First link:

<a href="hescript://demo1.MySecondDemo|1">This is the 1st link</a>

And second link:

<a href="hescript://demo1.MySecondDemo|2">This is the 2nd link</a>

Info

String parameters should only be used in links and JavaScript calls.

Using JavaScript

You may use HEScript together with JavaScript.

Please refer to the exeoutput object API for calling HEScript from JavaScript.

Using PHP

ExeOutput provides you with two built-in php functions to call HEScript functions:

exo_runhescriptcom ( string $script )

$script is the reference to the script's name and function to call.

string exo_return_hescriptcom ( string $script , string $defaultvalue )

Please refer to the corresponding ExeOutput php internal functions topic for samples.