jsexecutor class : Execute(string,bool) method


Executes JavaScript code.


instance.Execute(string jscode, bool complement)


stringjscodeJavaScript code.
boolcomplementWhether to make it to the immediate function.

Return value

stringReturn value from the JavaScript.

Sample code


jsexecutor jse; // For Main-browser


string result = jse.Execute("alert('hello world!');", true); // It show dialog and return "null".


result = jse.Execute("return 'hello world!';", true); // It occur an exception and return "null".


In the second argument, specifies whether to complemented the JavaScript code to the Immediately Invoked Function Expression, IIFE.

If true, it will be complemented. If false, it will not be complemented.

When it is complemented, it will be as follow.

return 'result'; -> (function (token){return 'result';}("0f8fbd59d9cb769fa16570867728950e"));

Please be careful, you may get the unexpected result depending on the complement.

For the method of IIFE, Please refer to Execution of JavaScript code: IIFE.

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


Copyright © Cooker All rights reserved.