Navigation: For Developers > Extend Functionality with HEScript >

Run and Call HEScript From JavaScript And HTML

 

 

 

 

📚 Script Usage Scenarios

 

🚀 Explore the power of scripting in HTML Executable, and take your applications to the next level!

 

Scripts in HTML Executable offer a wide range of possibilities, including:

 

ØDefining security profiles with Boolean conditions

ØCreating HTML links that execute scripts

ØImplementing JavaScript functions

ØResponding to global application events

 

In this comprehensive guide, we'll walk you through each of these use cases, providing clear instructions and even working demonstrations for a deeper understanding.

 

Leveraging Scripts with Security Profiles

 

Security profiles allow you to define "Boolean function result" conditions that call specific functions within a script. When you add such a condition to a security profile, you can choose the Boolean function you wish to execute. If the function returns true, the condition is considered fulfilled, and its associated actions and restrictions are enforced.

 

Harnessing the Power of HTML Links

 

HTML Executable enables you to call HEScript procedures and functions independently via HTML links. To do so, simply use the `hescript://` prefix instead of `http://` to signal the runtime module to execute an HEScript procedure or function. The format is as follows:

hescript:[scriptname].[functionprocedurename]

 

Here's an example:

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

 

You can even pass string parameters using a `|` separator. Just remember to properly encode non-ASCII characters of parameters. For instance, replace spaces in arguments by %20.

 

 For URL encoding, you can use this online tool.

 

Another Demonstration

 

Let's take a look at another example. In this case, we'll use string parameters in our links. Here's the script procedure:

 

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;

 

You can create two links with different parameters:

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

 

ØThis is the 1st link

ØThis is the 2nd link

 

Utilizing JavaScript Integration

 

Finally, you can seamlessly integrate HEScript with JavaScript. The global `htmlexe` JavaScript object allows communication between JavaScript scripts and HEScript: use these two JavaScript methods: `htmlexe.RunHEScriptCom` or `htmlexe.GetHEScriptCom` to communicate with HEScript scripts

 

WARNING: JavaScript implementation works asynchronously when invoking HEScript functions..

 

Calling HEScript procedures with JavaScript

 

 When you don't expect a result from an HEScript procedure, you can use `htmlexe.RunHEScriptCom`.

 

htmlexe.runHEScriptCom('[scriptname].[functionprocedurename]|param1|param2|....|paramN');

 

This works exactly as the hescript:// method for HTML links explained above; you have just to replace it by htmlexe.RunHEScriptCom(".....");

 

Examples:

htmlexe.RunHEScriptCom("hescript://UserMain.Procedure1");

 

<script>  
$(function() { $("#btnjs1").click( function() { htmlexe.RunHEScriptCom('hescript://UserMain.Procedure1'); } ); });
</script>  
<button id="btnjs1" class="btn btn-primary">Test Procedure 1</button>

 

Calling HEScript string functions with JavaScript

 

 When you expect the result from an HEScript string function, you must use `htmlexe.GetHEScriptCom` to execute and read the result with JavaScript. This function does not return the value itself: you must pass a callback JavaScript function that will receive the result. The callback should be a simple JavaScript  function with a single parameter that will receive the HEScript function's result.

 

htmlexe.GetHEScriptCom('[scriptname].[functionprocedurename]|param1|param2|....|paramN', callbackJS);

 

Example:

// Callback function
function DemoCallback2(content) { $('#result').text(content); }
 
// Main code:
htmlexe.GetHEScriptCom('hescript://UserMain.ReturnDate', DemoCallback2);

 

Once the UserMain.ReturnDate function returns the result, the JavaScript callback named DemoCallback2 is fired.

 

Example:

<script>  // Callback function
 function DemoCallback2(content) { $('#result').text(content); }
 
 $(function() { $("#btnjs2").click( function() { htmlexe.GetHEScriptCom('hescript://UserMain.ReturnDate', DemoCallback2); } ); });
</script>
<button id="btnjs2" class="btn btn-primary">Tell me the date</button>

 

Other examples

 

  Open the HTML Executable's Main Demonstration to see working examples

 

  Introduction to Scripting