Missing Documentation

There seems to be missing documentation regarding the “ExecuteJavaScript” function for the HTMLViewer.

The code provided is below, and I’m wondering how Xojo could have missed the three dot’s. There is no clear example on how to use this function.

Dim js As String . . . HtmlViewer1.ExecuteJavaScript(js)

the three dots would mean “create js to hold whatever javascript you mean to execute”

but depending on what you ant the javascript will be different

Would it be in string format? Or just type the javascript function?

The documentation is lacking in that regard; I have no idea how to create said javascript.

Of course it would be in string format. Build a string that contains the javascript you want to execute and pass it to the method. Just like SQL.

It’s been a long while since I did javascript and never used ExecuteJavaScript but it appears to run the js as if you had included it in a script tag on the page. I haven’t tested if vars or functions persist after the call. Anyways, here’s a demo that will add text to the top of whatever is loaded.

[code]//Add 2 buttons and an HTMLViewer

Sub Action() //PushButton1
HTMLViewer1.LoadURL(“https://forum.xojo.com”)
End Sub

Sub Action() //PushButton2

dim jsSrc As String

jsSrc = “document.body.insertBefore(document.createTextNode(”“Hello Xojo”"),document.body.firstChild);"

HTMLViewer1.ExecuteJavaScript(jsSrc)

End Sub[/code]

I agree that more should be explained about this, it’s sorta open what if any limitations there are or where this js fits into the DOM.

[quote=31527:@stuart s]It’s been a long while since I did javascript and never used ExecuteJavaScript but it appears to run the js as if you had included it in a script tag on the page. I haven’t tested if vars or functions persist after the call. Anyways, here’s a demo that will add text to the top of whatever is loaded.

[code]//Add 2 buttons and an HTMLViewer

Sub Action() //PushButton1
HTMLViewer1.LoadURL(“https://forum.xojo.com”)
End Sub

Sub Action() //PushButton2

dim jsSrc As String

jsSrc = “document.body.insertBefore(document.createTextNode(”“Hello Xojo”"),document.body.firstChild);"

HTMLViewer1.ExecuteJavaScript(jsSrc)

End Sub[/code]

I agree that more should be explained about this, it’s sorta open what if any limitations there are or where this js fits into the DOM.[/quote]

Thank you very much!

This is a very clear example on how to use this method :slight_smile: