My GWT app is designed to have an iframe with another web app (not GWT this time) embedded in it. This embedded app expects to be able to call some APIs in my parent app like so:
window.parent.f(function(result) { console.log("Result == " + result); });
How do I declare a JSNI function that can take that function as a parameter?
private static final void f(Consumer<String> onsuccess) {
onsuccess.accept("abcd");
}
public static native void installApi() /*-{
$wnd.f = function(onsuccess) {
@my.package.client.Example::f(...); // What goes in here?
}
}-*/;
Look at JsInterop. It's currently best and easiest approach to communicate between Java and JavaScript in GWT.
http://www.gwtproject.org/doc/latest/DevGuideCodingBasicsJsInterop.html
Beside that, there are security limitations when Iframe is loaded from different domain / port.
Calling a parent window function from an iframe
EDIT: Try this:
And call this by:
And most important that it's hidden in docs, you need to add this option to compile and superdev mode params.