HTMLViewer.ExecuteJavaScript

From Xojo Documentation

Method

HTMLViewer.ExecuteJavaScript(js As String)

New in 2011r4

Supported for all project types and targets.

Asynchronously executes the passed JavaScript in the context of the currently loaded page.

Notes

Attempting to execute JavaScript before the page finishes loading (or if no page is loaded) is undefined and is unlikely to work.

In order to call JavaScript on Windows using the Native renderer, a document must already be loaded into the HTMLViewer. If no document is loaded, an HTMLViewerException is raised.

Sample Code

This code will populate the search field on the wikipedia page (assuming it was previously loaded):

Var jsSrc As String
jsSrc = "document.forms[0].elements['search'].value=""xojo"";"
HTMLViewer1.ExecuteJavaScript(jsSrc)

This code writes text to the HTML document:

Var this As String
this = "document.writeln(""hello"");"
HTMLViewer1.ExecuteJavaScript(this)

See Also

ExecuteJavaScriptSync method.