How to call an htmlviewer page javascript function?


I haven’t been able to find an answer to this yet searching the forum.

I have a desktop app that has a window with an htmlviewer. I create the html for the page that includes CSS and JavaScript included in the html head and then load the page. The page displays as I expect and my JavaScript is working to initialize elements of the page.

But I have a JavaScript function on that page called ‘LoadData’ that is used to load existing data from a JSON object into fields on the html form. I am trying to call this JavaScript function like this:

theJS = “LoadData(” + Self.formData + “);”

But nothing happens. The formData does have my JSON data in it. I have tried using Native renderer as well as WebKit. Any ideas on how to call my LoadData JavaScript function?



Desktop app, Michel :slight_smile:

My question is what theJS looks like before you try to use ExecuteJavaScript. Set a breakpoint and see if the JSON is one big string, because it looks like it may not be getting encased in quotes (which might help if it’s a string rather than a javascript object)

As for “nothing happens”
Is that nothing happens as in it tries to parse LoadData as if it was empty and with no data it has no output, or does LoadData not even get run? There’s lots of different kinds of nothing happens.

[quote=125096:@Tim Parnell]Desktop app, Michel :slight_smile: [/quote]

Of course. Sorry.

I missed the quotes, thanks. I added single quotes around the data string since it contains double quotes.

The other issue that I think was affecting this was that the page load was probably not complete when the HTMLFormViewer.ExecuteJavaScript was happening and therefore the data does not load. HTML form fields were still empty. By placing the code in a window button and testing I can see that the data does load. So I just need to move the initial call to load the data after I’m sure the HTML form has loaded.


Use the DocumentComplete event.

Thanks, that does the trick.