jsexecutor class : CallJSFunction(string,...) method

Description

Calls a JavaScript function.

Syntax

instance.CallJSFunction(string funcName, ...)

Arguments

ClassNameDescription
stringfuncNameA JavaScript function name.
...Arguments passed to the JavaScript function.

Return value

ClassDescription
stringA return value from the JavaScript function.

Sample code

Suppose you have the following JavaScript function in currently displayed page.

1:

function square(number) {

2:

return number * number;.

3:

}

Usage of the CallJSFunction(string,...) method is as follows.

1:

jsexecutor jse; // For Main-browser

2:

string funcName = "square";

3:

string result = jse.CallJSFunction(funcName, 5); // The result is '25'.

Notes

First argument should specify only a JavaScript function name. In the above case, the first argument is "square".

You can place the arguments required by the JavaScript function to the second and subsequent arguments. These arguments should be the int, long, real, string, or bool class.

There is no limit the number of second and subsequent arguments. You can place the arguments in the order required by the JavaScript function.


Please note that the return value is string.

If the result is a number, the number will be returned as a string. Example: 1-> '1' , 1.05-> '1.05'.

If the result is a boolean value, the value is returned as a string. Example: true -> 'true' / false -> 'false'

If the result is a string, the string will be enclosed in double quotes and returned. Example: 'Returned string' -> '"Returned string"'.

If the result is null, undefined, array, object, function object, or unevaluable, the string 'null' is returned.

The 'null' is also returned if the run raises an exception.

Links for reference

None.

Copyright © Cooker All rights reserved.