Method XbpHTMLViewer2():executeScript() Foundation
Execute JavaScript code in the current document.
:executeScript( <cScript> ) --> oAsyncResult
A AsyncResult() object which can be used to wait for script execution to complete and to retrieve the operation result. The result is returned as a JSON-encoded string. The function JsonDecode() can be used to convert this string into the application's character set. If no value is returned by the script, return is "null". If the script contains a syntax error or if a runtime error occurs during execution, the return also is "null".
The method :executeScript() is used for executing JavaScript code in the context of the current document. This is useful for triggering actions or for accessing elements or values within the page (DOM access).
:executeScript() executes the JavaScript code asynchronously and the result of the operation is not available until script execution has completed. The method returns a AsyncResult() object which can be used to wait for the operation to complete and to retrieve the operation result.
The result of the script execution can be obtained using AsyncResult():get() and is returned in the form of a JSON-encoded string. The function JsonDecode() can be used to convert this string into the application's character set. The following code snippet illustrates the usage of :executeScript().
// Display a message in the current document (does not wait for operation to complete)
oHTMLViewer2:executeScript( "alert('Message from application')" )
// Get the HTML in the body element (waits for operation to complete)
cHTML := oHTMLViewer2:executeScript("document.body.innerHTML"):get()
The JavaScript code executes within the global context of the current page and will fail unless the document is fully loaded. When navigating to another page, for example, :executeScript() should not be called before the navigation is finished and the :navigateComplete event has been received by the application.
If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.