How to get generated HTML from HTMLViewer

What is the current preferred method to get generated output from HTMLViewer? I have a few JS parsers (js-sequence-diagram, which needs to process my source HTML and generates output that I want to capture so that I can incorporate into a larger HTML document from multiple sources. Thanks for advice on how best to accomplish.


Robert, just a detail. Unless you develop cross platform, it is a good idea to post in the channel corresponding to your platform : Mac, Windows, Linux. That way, answers will be tailored for that particular case. In this instance, the solution varies.

Initially, I am asking about Windows, but I am also looking to compile for Linux as well.

The way to send data back to Xojo from inside HTMLViewer on Windows and LInux is to change the title in JS, and catch that change in the TitleChanged event.

This in JS will trigger the title change :

document.title = "This is my message";

You need to discriminate between your own code, and the normal title. To do so, I use a prefix, for instance “data:”

document.title = "data:This is my message";

That way in TitleChanged I can do

dim Msg as string If Left(newTitle, 5) = "Data:" then Msg = Replace(newTitle, "Data:", "") // Do whatever you need with Msg end if

Do remember the 4kb limit.

Indeed. If necessary use JS Slice to send smaller chunks.

I am needing to return the generated output from processed HTML. It seems like there should be a way to save the generated HTML out rather than passing via a 4kb title value. Other options?



I load my html and the parser runs and presents the output diagram in html. How do I, 1) know when the js has finished executing ? and 2) trigger an event to copy the output into the title? Any example projects available?

Thank you,

You could create a http socket with JavaScript and possibly catch the response with a serversocket.listen . Just an idea, I have never tried this.

Edit: I know this works with the handleUrl in WebApps.

You’ll need to go learn Javascript.

#1 can be accomplished by making a hook in the javascript that sends a message out to Xojo when the js has finished.
#2 you would create a function in Javascript to do so, or you can create an anonymous js function and execute it from Xojo with ExecuteJavascript. Then capture the data in TitleChanged, and piece it back together.