ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

This content has been translated automatically.  Click here  to view the French version.
Help / WLanguage / WLanguage functions / Standard functions / Windows functions / Miscellaneous WINDEV functions
  • Calling WLanguage code from the JavaScript code
WINDEV
WindowsLinuxJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac Catalyst
Others
Stored procedures
Runs JavaScript code in the context of the Web page displayed by an HTML Display control.
Warning The "Don't allow the execution of JavaScript scripts" option must be unchecked in the "General" tab of the HTML Display control description window.
Example
JSCode is string = [
var Now = new Date();
alert('We are on: ' + Now);
]
ExecuteJS(HTM_MyHTMLControl, CodeJS)
JSCode is string = [
var Now = new Date();
var result = '' + Now;
''+Now;
]
ExecuteJS(HTM_MyControl, JSCode, ExecuteJS_Callback)
INTERNAL PROCEDURE ExecuteJS_Callback(bSuccess is boolean, ReturnValue is string)
	IF NOT bSuccess
		Error(ErrorInfo())
		RETURN
	END
	Info(ReturnValue)
END
Syntax
<Result> = ExecuteJS(<HTML Display control> , <JavaScript code> [, <WLanguage procedure>])
<Result>: Boolean
  • True if the JavaScript code was transmitted for execution to the control,
  • False otherwise.
<HTML Display control>: Control name
Name of the HTML Display control on which the JavaScript script will be executed.
<JavaScript code>: Character string
JavaScript code to execute. This code is run in asynchronous mode. The result of the code execution can be retrieved via the <WLanguage procedure> parameter.
The value returned by the JavaScript code corresponds to the value of the expression found in the last line of code. Do not use "return". The expression to be retrieved must be a string.
<WLanguage procedure>: Optional procedure name
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 is string)
This procedure is called once the JavaScript code has been executed. The parameters of this procedure are:
  • <bSuccess>:
    • True if the JavaScript code was successfully executed,
    • False if the execution of JavaScript code generated an error (e.g., error in the JavaScript code). In that case, to get more details on the error, use ErrorInfo.
  • <ReturnValue> contains the value of the last expression of the JavaScript code (returned value).
Remarks

Calling WLanguage code from the JavaScript code

You can call WLanguage code from a JavaScript code executed via ExecuteJS or via the HTML code contained in the HTML Display control. The following operations must be performed:
  1. In the "General" tab of the HTML Display control, check "Allow calling WLanguage code from 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(<WLanguage Procedure Name> [, <Parameter 1> [, ... [, <Parameter N>]]])
    where:
    • <WLanguage procedure name> corresponds to the name of the procedure to be executed.
    • <Parameter N> corresponds to the different parameters to be passed to the procedure:
      • Number of parameters:
        • Windows between 0 and N.
      • Type of parameters:
        • Windows The parameters of the WLanguage procedure will be passed according to their type: boolean, string, number, null.
Example:
  • WLanguage procedure
    PROCEDURE ProcFromJS(t)
    ToastDisplay("Called from JS: " + t)
  • Code of the 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.
Business / UI classification: UI Code
Component: wd300obj.dll
Minimum version required
  • Version 23
This page is also available for…
Comments
Video ExecuteJs
https://youtu.be/_ZTkcLnfyYY

https://windevdesenvolvimento.blogspot.com/2019/02/dicas-2029-windev-dicas-87-executejs.html

sCODIGO_JAVA_SCRIPT is string=[
alert( ' Mensage do Java Script dentro do Windev ' );
]

ExecuteJS(HTM_CONTROL,sCODIGO_JAVA_SCRIPT)
amarildo
28 Feb. 2019

Last update: 01/16/2025

Send a report | Local help