Calling Javascript

Hello, I am using the WebBrowserComponent to render parts of my UI. And it works fine to intercept the clicks in the webUI.

But the other way is harder, how do I update IT?

For instance if the user select a menu option, I want for example expand a section in the web document (change visibility of a div element).

Refreshing the the whole web page is not a solution in my case.

I was hoping for a simple way to call a javascript function, like:

webBrowserComp.CallJavaScript(T(“expandDiv”),args);

But I can’t find something like that.

Then I thought maybe I add the functionality myself… :slight_smile: And I dug around in the source files, but I have a hard time to follow all that COM code, and the mac stuff is even harder.

So to my question (jules):
Is this something you could add to your todo list?

I could try to help you out with the windows part, but the with the mac stuff i am lost.

Regards Okku Touronen

It can already do that.

All you need to do is to make your JS create an object with some methods in it, then call the plugin and pass it that object. The plugin can then keep a pointer to that object and call its methods, which can do whatever you need.

:slight_smile: Ok great!

I dont fully understand that, sorry for that.

Do I need to create a plugin?

Do you know where I can find any example of this? (I have searched the forum but not found anything)

Hello again, sorry if I didn’t make it clear that i am developing an application not a browser plug-in.

[WIN]
I have looked around and found Mark Finkle’s blog how to do a simple call to a javascript function. http://bit.ly/2wiLmc

You just need the to get the IHTMLDocument interface in some way from the webbrowser control component. I can look more into this.

[MAC]
In the Mac Dev Center i found following:
http://bit.ly/r3qna

If you just know a little objective-c it seems straight forward

I also found that QT (which use webkit) use the following syntax:

webView->mainFrame()->evaluateJavaScript(“map.setCenter(bounds.getCenter());”);

Which is a simple way to add this functionality, you leave the parsing to the javascript eval method (I think they have implemented like that). This is ofcourse possible with the win version to.

Best Regards Okku Touronen

Ah, sorry, I misread your post, (as you clearly figured out…)

It’s not something I’d thought of adding, but could be a good feature. Bit too busy on other things right now, but if you have any bits of code to do it, please chuck them in my direction!

Ok Jules, I will look into it, thanks for a great framework.