PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

This page concerns the 23 + version of WINDEV, WINDEV Mobile. Upgrade your version.
  • Use conditions
  • Calling WLanguage code from 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
ExecuteJS (Function)
In French: ExécuteJS
Runs Javascript code in the context of 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.
Example
JSCode is string = [
var now = new Date();
alert( 'Today is: ' + now);
]
ExecuteJS(HTM_MyHTMLControl, JSCode)
WINDEV
codeJS is string = [
var now = new Date();
return now;
]

ExecuteJS(HTM_MyControl, JSCode, ResultJSExecution)

INTERNAL PROCEDURE ResultJSExecution(bSuccess is boolean, ReturnValue)
IF not bSuccess
Error(ErrorInfo())
RETURN
END
Info(ReturnValue)
END
Syntax
<Result> = ExecuteJS(<HTML control> , <Javascript code> [, <Procedure Name>])
<Result>: Boolean
  • True if the Javascript code was transmitted for execution to the control,
  • False otherwise.
<HTML control>: Character string (with or without quotes)
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.
<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.
      AndroidiPhone/iPad Note:
      • Android A detailed error is returned.
      • iPhone/iPad A generic error is returned.
  • <ReturnValue> contains the return value of code execution (if this code returns a value).
Remarks
Android

Use conditions

This function is available on the devices running Android version 4.4 or later (api level 19).
The procedure will not be called if the function is used with an earlier system version.
To find out the version of Android system on which the application is run, use SysAndroidVersion.

Calling WLanguage code from Javascript code

You have the ability to call WLanguage code from a Javascript code run by 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.
Components
WINDEVReports and Queries wd230obj.dll
Android wd230android.jar
Minimum required version
  • Version 23
This page is also available for…
Comments
Click [Add] to post a comment