EvaluateJavascriptSync
PowerScript function
Description
Executes JavaScript synchronously.
Applies to
Syntax
|
1 |
controlname.EvaluateJavascriptSync (string script{, ref string result{, ref string error}}) |
|
Argument |
Description |
|---|---|
|
controlname |
The name of the WebBrowser control. |
|
script |
The JavaScript to be evaluated. The JavaScript cannot have If there are multiple JavaScript statements, only the last |
|
result |
The result of script execution. The execution result is For example, {“type”:”double”,”value”:1585620350123};//returns a {“type”:”string”,”value”:”12d6_1585674123456_74563″};//returns |
|
error |
The error information if an error occurs during execution. {“type”:”error”,”value”:”Uncaught TypeError: Cannot read |
Return value
Integer.
Returns 1 if it succeeds and -1 if an error occurs.
Examples
The following example executes a JavaScript and gets the current
time (double type):
|
1 2 3 4 5 |
String ls_JS, ls_Result, ls_Error Integer li_Return ls_JS = "(new Date()).getTime();" li_Return = wb_1.EvaluateJavascriptSync(ls_JS, ls_Result) |
The following example executes a JavaScript and returns an
array:
|
1 2 3 4 5 |
String ls_JS, ls_Result, ls_Error Integer li_Return ls_JS = "new Array(123, new Date(), 'Appeon', 2 > 1)" li_Return = wb_1.EvaluateJavascriptSync(ls_JS, ls_Result, ls_Error) |
The following example executes a JavaScript and parses the result (a
JSON string) via the JSONParser object:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
String ls_JS, ls_Result, ls_Error, ls_Type Integer li_Return DateTime ldt_DateTime JsonParser lnv_JsonParser Long ll_RootObject lnv_JsonParser = Create JsonParser ls_JS = "function getNow(){return (new Date());} getNow();" li_Return = wb_1.EvaluateJavascriptSync(ls_JS, ls_Result, ls_Error) If li_Return = 1 Then lnv_JsonParser.LoadString(ls_Result) ll_RootObject = lnv_JsonParser.GetRootItem() ls_Type = lnv_JsonParser.GetItemString(ll_RootObject, "type") ldt_DateTime = lnv_JsonParser.GetItemDateTime(ll_RootObject, "value") End If If IsValid(lnv_JsonParser) Then Destroy (lnv_JsonParser) |
See also