Call Script Procedure/Function |
Applies to HTML Viewer, IE Browser publications. Scripts have multiple possible uses: you can assign them to
In this topic, you will learn how to call functions/procedures from HEScript scripts. You also have live demonstrations with detailed samples.
Script associated to HTML pagesWith scripts associated to 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 a HTML link is clicked for instance). You can use these events to add your own actions using script commands. Scripts and security profilesWith 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. Using HTML Links
<a href="hescript://MyScript.Procedure1">Click here to execute my first function</a> Live Demonstration: try it yourself! We wrote a small script called "demo1" in the Script Manager which contains the following procedure: procedure MyFirstDemo; 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: Click here to execute this function
Example: hescript://MyScript.ProcedureA|test Live Demonstration: We are using a second example. The script procedure in "demo1" is: procedure MySecondDemo(cond: String); 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 the second link: <a href="hescript://demo1.MySecondDemo|2">This is the 2nd link</a>
Using JavaScriptYou may finally use HEScript together with JavaScript (in IE browser 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 method called runHEScriptCom. JavaScript syntax: window.external.runHEScriptCom('[scriptname].[functionprocedurename]|param1|param2|....|paramN'); This exactly works like the hescript:// method for HTML links; you have just to replace it by window.external.runHEScriptCom('.......'); Example: window.external.runHEScriptCom('hescript://MyScript.Procedure1');
You can also use this JavaScript function: function executecom(sname) 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. |