Important Notice - Forums is archived
To simplify things and help our users to be more productive, we have archived the current forum and focus our efforts on helping developers on Stack Overflow. You can post new questions on Stack Overflow or join our Discord channel.

Vaadin lets you build secure, UX-first PWAs entirely in Java.
Free ebook & tutorial.
Invoke Javascript in embeded html
Hi,
I have an external html page embedded in vaadin. What I need is: when triggering the listeners of the vaadin UI components, the javascripts in the embedded html page can be executed.
I read that the embedded html are within an iframe. If I am able to obtain the element id of this iframe. Should I be able to do the following?
getWindow().executeJavaScript("document.getElementById('" + iframeId + "').contentWindow.myJsFunction();");
If this is possible, my 2nd question is whether it is possible to obtain the iframe id in vaadin? Or the GWT obfuscator does a great job to prevent me from doing so?
Many Thanks.
I have figured out how to do it. The following is what I have done. I hope it helps if other people have similar problems.
It requires to pass a piece of javascript code to the executeJavaScript() function.
In this piece of JS code. I did
1. iterate through window.frames, which contain the iframe that embeds my external html.
2. for each frame, i obtain the tile of the frame: myframe.document.title. If the external html contains a <title> tag. myframe.document.title should contain the value of the <title> tag. so I can find which frame is the iframe that contains my external html page.
3. call myframe.myJsFunction()
I can see my WebGL 3D cubes start rotating if I click a vaadin button that executes the above JS code. :grin: