NotQuiteThereYet
NotQuiteThereYet

Reputation: 497

OpenWebkitSharp for .NET -- any trick for getting Javascript to work with it in this scenario?

I am using the OpenWebkitSharp browser in a VB.NET project. What I am trying to do is use WebkitBrowser1.Navigate to display some HTML in the browser "on the fly". This works great for basic HTML, but Javascript does not appear to work at all in this scenario. For example, I have...

WebKitBrowser1.DocumentText = "<!DOCTYPE html><html><head><script>alert('This is an alert'); </script></head><body><p>This is some text</p></body></html>"

The body text appears just fine, but there is never a Javascript alert. I made sure that Javascript is enabled in the Webkit browser, so that's not the issue.

If I use the Navigate method to display a local page that contains Javascript (ie WebkitBrowser1.Navigate("path/to/local/file"), then the Javascript works perfectly. But it doesn't work at all when setting the HTML using WebKitBrowser1.DocumentText.

For this particular project, I need to generate the HTML code and display it "on the fly", so I can't use WebKitBrowser1.Navigate. I have to use WebkitBrowser1.DocumentText instead (or something similar).

Any ideas?

Or might there be a better way to accomplish this?

Thanks!

Upvotes: 0

Views: 890

Answers (1)

Nate S.
Nate S.

Reputation: 69

I ran into a similar situation recently, and while I'm still looking for that solution that allows what you're describing, here's what I decided to do as a workaround:

-Save HTML to temporary file -Load temp file into WebKit control on form.

I'm considering making my own modifications to OpenWebKitSharp however, to see if I can make this happen. Basically, it seems like HTML loaded through DocumentText follows a different render path than loaded through Navigate.

Upvotes: 0

Related Questions