# Calling Javascript

**URL:** <https://forum.juce.com/t/calling-javascript/4505>\
**Category:** General JUCE discussion\
**Created:** [November 12, 2009, 10:33pm UTC](https://forum.juce.com/t/calling-javascript/4505 "2009-11-12T22:33:31Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Okku\_Touronen](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/okku_touronen/32/417_2.png) [@Okku\_Touronen](https://forum.juce.com/u/Okku_Touronen)\
**Post date:** [November 12, 2009, 10:33pm UTC](https://forum.juce.com/t/calling-javascript/4505/1 "2009-11-12T22:33:31Z")

</div>

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… 🙂 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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 12, 2009, 10:40pm UTC](https://forum.juce.com/t/calling-javascript/4505/2 "2009-11-12T22:40:56Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![Okku\_Touronen](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/okku_touronen/32/417_2.png) [@Okku\_Touronen](https://forum.juce.com/u/Okku_Touronen)\
**Post date:** [November 12, 2009, 10:52pm UTC](https://forum.juce.com/t/calling-javascript/4505/3 "2009-11-12T22:52:27Z")

</div>

🙂 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)

---

<div class="post-metadata">

**Author:** ![Okku\_Touronen](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/okku_touronen/32/417_2.png) [@Okku\_Touronen](https://forum.juce.com/u/Okku_Touronen)\
**Post date:** [November 13, 2009, 9:08am UTC](https://forum.juce.com/t/calling-javascript/4505/4 "2009-11-13T09:08:07Z")

</div>

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](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](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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [November 13, 2009, 9:57am UTC](https://forum.juce.com/t/calling-javascript/4505/5 "2009-11-13T09:57:22Z")

</div>

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!

---

<div class="post-metadata">

**Author:** ![Okku\_Touronen](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/okku_touronen/32/417_2.png) [@Okku\_Touronen](https://forum.juce.com/u/Okku_Touronen)\
**Post date:** [November 13, 2009, 10:42am UTC](https://forum.juce.com/t/calling-javascript/4505/6 "2009-11-13T10:42:04Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://forum.juce.com/u/jules)\
**Post date:** [May 12, 2017, 9:50am UTC](https://forum.juce.com/t/calling-javascript/4505/7 "2017-05-12T09:50:35Z")

</div>

Closed on May 12, 2017, 9:50am UTC


