javascript window.opener not working

394 views
Skip to first unread message

gabidp

unread,
Nov 24, 2008, 8:30:11 AM11/24/08
to Google Web Toolkit
Hi!

I have a window which opens a popup with a native javascript method:
public static native void open_new_window(String url, String name,
String options) /*-{
open(url, name, options);
}-*/;

This new window has a button, and when someone clicks it, I want to do
something on the original window with this function:
public native void test()
/*-{
$wnd.opener.document.forms[0].testForm.value = "AA"
}-*/;

The problem seems to be that $wnd.opener does not reference my
original window. How can I do that?

Thank you!

Sumit Chandel

unread,
Nov 26, 2008, 4:41:39 PM11/26/08
to Google-We...@googlegroups.com
Hi gabidp,

I believe the reason why you're unable to access the opener attribute defined on the $wnd object is because of the way you're creating the popup in the first open(url, name, options) call.

The reason why we keep the $wnd reference around is because GWT applications load up in their own <iframe>, meaning that references to the regular window object are local to the <iframe> rather than the body of the page.

By calling open(url, name, options), you're actually invoking window.open(url, name, options) from within the <iframe> context. This means that the popup might also limited to the same scope, so references to $wnd attrributes won't resolve.

Try replacing the open(url, name, options) call by $wnd.open(...) and see if that works.

Hope that helps,
-Sumit Chandel
Reply all
Reply to author
Forward
0 new messages