Applies to HTML Viewer, IE Browser publications.
Scripts have multiple possible uses: you can assign them to
HTML pages
security profiles (Boolean conditions)
global publication events.
In this topic, you will learn how to call functions/procedures from HEScript scripts. You also have working demonstrations with detailed samples.
The internal HTML editor has a tool that lets you visually add links and JavaScript code to HTML pages that call HEScript functions.
With scripts associated with HTML pages, the runtime module will automatically call some pre-defined procedures or functions called events when a related event occurs (when the page is loaded or an HTML link is clicked for instance). You can use these events to add your own actions using script commands.
With security profiles, you can add “Boolean function result” conditions that actually call a Boolean function from a given script: you are prompted to select the Boolean function you want when you add such a condition to a security profile. If the function returns true, the condition is considered as fulfilled and its associated actions/restrictions are executed.
You can call HEScript procedures and functions independently via HTML links. You need to use the hescript://
prefix instead of http://
to inform the runtime module 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>
So click the link to see what happens:
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
Important: please properly encode non-ASCII characters of parameters (HTML Executable 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>
String parameters should only be used in links and JavaScript calls.
You may finally use HEScript together with JavaScript (in IE publications).
The Internet Explorer JavaScript model has a special function window.external that allows JavaScript scripts to communicate with HEScript scripts.
Window.external methods are described here. We will only introduce one of the methods called runHEScriptCom.
JavaScript syntax:
window.external.runHEScriptCom('[scriptname].[functionprocedurename]|param1|param2|....|paramN');
This exactly works like the hescript://
method for HTML links; you just have to replace it by window.external.runHEScriptCom('.......');
Example:
window.external.runHEScriptCom('MyScript.Procedure1');
You can therefore call any HEScript procedure or function at any time from JavaScript.
You can also use this JavaScript function:
function executecom(sname)
{
window.external.runHEScriptCom(sname);
return 0;
}
Live Demonstration:
Instead of using a link, we use a button:
<input type="button" onclick="javascript:window.external.runHEScriptCom('demo1.MySecondDemo|1');
" value="Link 1" name="B1">
The result is:
It exactly behaves like the link of the previous example.
If you want to call an HEScript function that returns a string, use window.external.getHEScriptCom instead.
See window.external methods for JavaScript.
Copyright G.D.G. Software 2019. All rights reserved