PC SOFT

WINDEVWEBDEV AND WINDEV MOBILE
ONLINE HELP

Home | Sign in | English UK

  • Calling WLanguage code from the Javascript code
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
<Html control>.ExecuteJS (Function)
In french: <Champ Html>.ExécuteJS
Runs Javascript code in the context of the Web page displayed by an HTML control.
Caution: The option "Allow the execution of JavaScript scripts" must be checked in the "General" tab of the description window of HTML control. Caution: The option "Forbid the execution of JavaScript scripts" must be unchecked in the "General" tab of the description window of HTML control.
Example
JSCode is string = [
var now = new Date();
alert( 'Today is: ' + now);
]
HTM_MyHTMLControl.ExecuteJS(codeJS)
JSCode is string = [
var now = new Date();
now;
]
 
HTM_MyHTMLControl.ExecuteJS(codeJS, ResultJSExecution)
 
INTERNAL PROCEDURE ResultJSExecution(bSuccess is boolean, ReturnValue)
IF NOT bSuccess
Error(ErrorInfo())
RETURN
END
Info(ReturnValue)
END
Syntax
<Result> = <HTML control>.ExecuteJS(<Javascript code> [, <Procedure name>])
<Result>: Boolean
  • True if the Javascript code was transmitted for execution to the control,
  • False otherwise.
<HTML control>: Control name
Name of HTML control on which the Javascript script will be run.
<Javascript code>: Character string (with quotes)
Javascript code to run. This code is run in asynchronous mode. The result of code execution can be retrieved via the <Procedure Name> parameter.
The value returned by the Javascript code corresponds to the value of the expression found on the last line of Javascript code.
<Procedure name>: Character string (with or without quotes)
WLanguage procedure ("callback") used to find out the result of code execution. This procedure has the following format:
PROCEDURE <Procedure Name>(bSuccess is boolean, <ReturnValue>)
This procedure is called once the Javascript code has been run. The parameters of this procedure are:
  • <bSuccess>:
    • True if the Javascript code was successfully run,
    • False if the execution of Javascript code triggered an error (error in the Javascript code for example). To find out the error details, use ErrorInfo.
  • <ReturnValue> contains the return value of code execution (if this code returns a value).
Remarks

Calling WLanguage code from the Javascript code

You have the ability to call WLanguage code from a Javascript code run by <Html control>.ExecuteJS or via the HTML code found in the HTML control. The following operations must be performed:
  1. In the "General" tab of HTML control, check "Allow the WLanguage call from the HTML code (JavaScript WL.Execute function)".
  2. In the HTML code of control, use WL.Execute to run a WLanguage procedure. The following syntax must be used:
    WL.Execute(<Name of WLanguage Procedure>, <Parameters>)
    where:
    • <Name of WLanguage Procedure> corresponds to the name of procedure to run.
    • <Parameters> corresponds to a character string that will be passed to the procedure.
Example:
  • WLanguage procedure
    PROCEDURE ProcFromJS(t)
    ToastDisplay("Called from JS: " + t)
  • Code of HTML control:
    s is string = [
    <html>
    <head>
    <title> A simple example
    </title>
    <script>
    function myFunction()
    {
    WL.Execute("ProcFromJS","titaa");
    }
    </script>
    </head>
    <body>
    <h1> This is an HTML page </h1>
    <p id="demo">A paragraph</p>
    <button type="button" onclick="myFunction()">Try</button>
    </body>
    </html>
    ]
    HTM_NoName1 = s
Related Examples:
WM HTML Dialog Cross-platform examples (WINDEV Mobile): WM HTML Dialog
[ + ] This example explains how to dialog with an HTML control.
It is using the WLanguage "ExecuteJS" function and the Javascript "WL.Execute" function.
Component : wd240obj.dll
Minimum version required
  • Version 23
This page is also available for…
Comments
Click [Add] to post a comment