public class foo implements EntryPoint {
public void onModuleLoad() {
Button button = new Button ("open window");
button.addClickListener(new buttonClicklistener());
RootPanel.get().add(button);
}
private class buttonClicklistener implements ClickListener {
public void onClick(Widget sender) {
openWindow();
}
}
private native void openWindow() /*-{
var window = $wnd.open("", "_blank");
if (window.opener == null) window.opener = self;
window.document.createElement("body");
window.document.body.innerHTML = "<a href=\"javascript:
window.opener.sayHello();\">say hello</a>";
$wnd.sayHello = function () { @com.test.client.foo::sayHello()() };
}-*/;
public static void sayHello() {
Window.alert("hello");
}
}
Now the problem is that this works perfectly in internet explorer, but
not in firefox. There I get an exception: no authorization to read the
property Window.sayHello (translated from dutch). I know this has
something to do with the fact that firefox doesn't allow calls from a
different origin. Isn't there a way to make sure firefox knows this
new window is from the same source?
In my application I want to open a new window and in this window I
want to have a link which calls a function from my application. Below
you can find an example of how this would look like.
public class foo implements EntryPoint {
public void onModuleLoad() {
Button button = new Button ("open window");
button.addClickListener(new buttonClicklistener());
RootPanel.get().add(button);
}
private class buttonClicklistener implements ClickListener {
public void onClick(Widget sender) {
openWindow();
}
}
private native void openWindow() /*-{
var window = $wnd.open("", "_blank");
if (window.opener == null) window.opener = self;
window.document.createElement ("body");
Many thanks for your solution. It works perfect both in firefox and
IE. Although I knew more or less the source of the problem, I don't
think I would've found the solution myself.
Meanwhile you also solved something else I didn't understand, because
even with my previous version, I needed an alert after creating the
window to make it work in hosted mode. It seems in hosted mode, even a
blank url needs some time to be created.
Thanks again!
Largo