HTMLViewer.ExecuteJavascript.... Once again.....

Fails…

Docs code:

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

Result: NilObectException

My Code

  Dim This As String
  This = "document.write(""hello"");"
  HTMLViewer1.ExecuteJavaScript(Hello)

Result: NilObjectException.

Native render engine causes the NilObjectException and on WebKit, the action doesn’t do anything.

Why is this happening?

I think that

HTMLViewer1.ExecuteJavaScript(Hello)

should be

HTMLViewer1.ExecuteJavaScript(This)

-_- Thanks.

I’ll try it out later.

Nope. Doesn’t work.

dim this as string this = "document.writeln(""hello"");" HTMLViewer1.ExecuteJavaScript(this)

Code causes crash. I knew it wouldn’t work as the code from the documentation wouldn’t work. Both (docs and mine) throws a NilExceptionError. Also tried just “write” and still crashes.

Where are you running the code? Web or desktop? What OS?

I put your code above on a PushButton and when I press it, “hello” is displayed in HTMLViewer1 (on OS X).

[quote=39874:@Paul Lefebvre]Where are you running the code? Web or desktop? What OS?

I put your code above on a PushButton and when I press it, “hello” is displayed in HTMLViewer1 (on OS X).[/quote]

Please don’t tell me it’s Windozes screwing up. I’ll try a build version.

Build version fails. It must be Windoze.

I’m running it on a Desktop app.

I do get a NilObjectException when I run on Windows if I have the HTMLViewer set to use the Native renderer. If it is set to use WebKit, it works.

The “native renderer” uses the Internet Explorer engine. Maybe it’s DOM is different?

This seems like a bug. I created <https://xojo.com/issue/30127>, which William is going to look at.

[quote=39885:@Paul Lefebvre]I do get a NilObjectException when I run on Windows if I have the HTMLViewer set to use the Native renderer. If it is set to use WebKit, it works.

The “native renderer” uses the Internet Explorer engine. Maybe it’s DOM is different?[/quote]

Thanks!
Maybe Xojo should just ditch IE and pre-include WebKit with app builds. Ditching IE would also boost the “cross platform-ability”.

Including WebKit increases the app size substantially (20-40MB, IIRC).

But I agree: for Best Results™, use WebKit.

OK, it turns out the native renderer has to first have a document loaded before you can execute any JavaScript.

So with this in the HTMLViewer1.Open event handler:

Me.LoadPage("<html></html>", GetTemporaryFolderItem)

Then this code in a button works:

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

A future release will raise an HTMLViewerException rather than a NilObjectException if no document is loaded. And the LangRef has been updated with this information.