In addition to its own HEScript scripting language, ExeOutput for PHP extends the browser’s environment with a special exeoutput JavaScript object. This API allows you to interact with and control the application directly from your HTML pages.
For instance, the following JavaScript code will close the application:
exeoutput.RunHEScriptCode('ExitPublication;');Asynchronous Operations
The exeoutput methods operate asynchronously. They do not return values directly. Instead, results are passed to a callback function that you specify in the method call. See the examples below for details.
exeoutput Methods #
| Method | Prototype | Description |
|---|---|---|
CloseCurrentWindow | exeoutput.CloseCurrentWindow() | Closes the current window. May prompt the user before closing. |
exportPDF | exeoutput.exportPDF(filename) | Exports the current page to a PDF file specified by filename. WebView2 only. For CEF, use window.exportPDF(). |
moveTo | exeoutput.moveTo(x, y) | Moves the current window to the specified x and y coordinates. WebView2 only. For CEF, use window.moveTo(). |
resizeTo | exeoutput.resizeTo(width, height) | Resizes the current window to the specified width and height. WebView2 only. For CEF, use window.resizeTo(). |
GetGlobalVariable | exeoutput.GetGlobalVariable(Name, DefaultValue, Callback) | Retrieves the value of the global variable Name. If not found, DefaultValue is returned. The result is passed to the Callback function. See GetGlobalVar. |
SetGlobalVariable | exeoutput.SetGlobalVariable(Name, Value, IsStored) | Sets the global variable Name to Value. If IsStored is true, the variable is persistent (saved and reloaded on restart). See SetGlobalVar. |
RunHEScriptCom | exeoutput.RunHEScriptCom(ComLine) | Executes an HEScript procedure or a function without a return value. Similar to the hescript:// protocol. |
RunHEScriptCode | exeoutput.RunHEScriptCode(Code) | Compiles and executes the given string of HEScript Code. |
GetHEScriptCom | exeoutput.GetHEScriptCom(ComLine, Callback) | Executes an HEScript function and passes its string result to the Callback function. See usage example below. |
GoToPage | exeoutput.GoToPage(URL, Window) | Navigates to the specified URL. The Window parameter is not used and should be an empty string. |
GetString | exeoutput.GetString(ID, Callback) | Retrieves a resource string by its ID and passes it to the Callback function. |
Examples #
Calling an HEScript Procedure #
To call an HEScript procedure (which does not return a value), use RunHEScriptCom.
For example, to call the HEScript procedure UserMain.MyProcedure:
exeoutput.RunHEScriptCom("UserMain.MyProcedure");Getting a Global Variable’s Value #
This example retrieves the value of the HEPHPPath variable and displays it in an alert.
<script language="JavaScript">
function DemoCallback(content) {
alert("PHP Path is: " + content);
}
// The default value "not found" will be used if the variable doesn't exist.
exeoutput.GetGlobalVariable('HEPHPPath', 'not found', DemoCallback);
</script>See the list of pre-defined global variables.
Calling an HEScript Function and Getting a Result #
Use GetHEScriptCom to execute an HEScript function and receive its return value in a callback.
JavaScript:
<script language="javascript">
// This callback function will receive the result from HEScript.
function DemoCallback(content) {
alert("The MD5 hash is: " + content);
}
// Calls the HEScript function "usermain.getit" and passes "password123" as a parameter.
exeoutput.GetHEScriptCom('usermain.getit|password123', DemoCallback);
</script>HEScript (UserMain script):
This script defines the getit function that will be called from JavaScript.
function getit(what: String): String;
begin
Result := MD5OfAString(what);
end;Displaying a Resource String #
This example retrieves a localized resource string and inserts it into a div element.
<div id="demo"></div>
<script language="JavaScript">
function DemoCallback(content) {
// Injects the localized string into the "demo" div.
document.getElementById('demo').innerHTML = '<p>' + content + '</p>';
}
// Replace "MyStringID" with the name of your resource string.
exeoutput.GetString("MyStringID", DemoCallback);
</script>Closing the Application #
// Executes the HEScript command to exit the application.
exeoutput.RunHEScriptCode('ExitPublication;');