Navigation: For Developers > Extend Functionality with HEScript > Sample Scripts >

How to call a javascript function from HEScript (toolbar, menubar)?





This guide explains how to call JavaScript functions from a button, menu item, or any general HEScript code in HTML Executable. Let's get started!


The Objective 🎯


You want to call a JavaScript function from your button, menu item, or any general HEScript code. How can you do that? The answer is simple: use the built-in HEScript function named `ExecuteHTMLScript`.


Step-by-Step Guide 📝


Step 1: Open Your HTML Executable Project 📂


Open your HTML Executable project and navigate to the Script Manager. Double-click the "UserMain" script to open the script editor:



Step 2: Use the ExecuteHTMLScript Function 🖋️


In the script editor, use the following code if you want to call your JavaScript code in the default homepage at startup:


procedure OnStartMainWindow;
  // When the main window is going to be displayed (just before the homepage is shown).


Don't forget to save your script!


Step 3: Include the Correct JavaScript Function 📚


Ensure that you have the correct JavaScript function in the default homepage (or any HTML page). For instance:


function sayHello(name) {
  alert('Hello ' + name + '!');


Final Step: Compile Your Project 🧪


Compile your project and that's it! You've successfully called a JavaScript function from your HTML Executable project.