Identify or get around popup blockers

1,262 views
Skip to first unread message

pady...@gmail.com

unread,
Jan 11, 2008, 1:36:01 AM1/11/08
to Google Web Toolkit

In my app, I would like to open a new window using Window.open. But if
there is a popup blocker like in Firefox, then the user has to
explicitly allow popup options to my site. Is there a way to
workaround this ? I see that in Google pages, one can "preview" the
page and in that case, I dont see the Firefox popup blocker coming up
but a completely new browser window shows up. What do I need to do in
my GWT app to get the same behavior ?

Thx

-- pady

Peter Blazejewicz

unread,
Jan 11, 2008, 8:11:55 AM1/11/08
to Google Web Toolkit

Jason Essington

unread,
Jan 11, 2008, 11:10:02 AM1/11/08
to Google-We...@googlegroups.com
Typically, even with popup blocking enabled, browsers will allow new
windows to be opened as a direct result of a user action, so if you
attempt to open a window in a ClickHandler for instance it should open
even if popup blocking is enabled.

I have one instance where I load a pdf document in a new window. but
first I need to make an RPC call to prepare the PDF. when I first
wrote the routine to perform that action, I opened the window in the
onSuccess method of the RPC's callback, which worked fine as long as
the popup blockers were not turned on. but when I moved the window
open code to the click listener of the submit button for my RPC, the
window would open regardless of the state of any popup blockers.

hope this helps

-jason

pady...@gmail.com

unread,
Jan 11, 2008, 12:22:16 PM1/11/08
to Google Web Toolkit

Hi Jason,

That is interesting. usually, we have a ClickListener where we do the
RPC stuff and then the callback will do the Window open. Can you give
an example of how you did the RPC and the Window open in the click
listener ? ( unless u simulated the click again from the onSuccess ).

Thx

-- pady

Jason Essington

unread,
Jan 11, 2008, 3:02:31 PM1/11/08
to Google-We...@googlegroups.com
Well, I had to use some JSNI magic to do it ...

In the click listener I needed to open a new window, but also keep a reference to it so I could later set its url in onSuccess

I use a utility class that has a static method for this:

   public static native JavaScriptObject newWindow(String url, String name, String features)/*-{
      var window = $wnd.open(url, name, features);
       return window;
   }-*/;

so, in my Click handler I do something like:

JavaScriptObject window = WindowUtil.newWindow("", "file_download", "");

then I create my callback supplying the window reference for use later
cb = new FileDownloadCallback(window);

then call the RPC as normal. at this point, there's a new empty window that has been opened, and the rpc has been sent off.

in the onSuccess method I set the URL (location) of the window that I created in onClick using another JSNI method in the utility class:

   public static native void setWindowTarget(JavaScriptObject window, String target)/*-{
      window.location = target;
   }-*/;

Something like

WindowUtil.setWindowTarget(window, urlFromResponse);


That's pretty much it, and seems to get around popup blockers.

-jason

pady...@gmail.com

unread,
Jan 11, 2008, 3:26:52 PM1/11/08
to Google Web Toolkit

Nice. I will give it a try.

Thx

-- pady

pady...@gmail.com

unread,
Jan 11, 2008, 5:08:30 PM1/11/08
to Google Web Toolkit

Thx. Works great.

-- pady

Yegor

unread,
Jan 13, 2008, 4:59:44 PM1/13/08
to Google Web Toolkit
Alternatively, you could use a PopupPanel or a Dialog instead of
opening a new window. All depends on your application's needs.

On Jan 11, 3:08 pm, "padysr...@gmail.com" <padysr...@gmail.com> wrote:
> Thx. Works great.
>
> -- pady

M

unread,
Nov 7, 2012, 5:17:11 PM11/7/12
to google-we...@googlegroups.com, Google Web Toolkit
Hi I was wondering if there is a work around for this issue? Above solution doesn't work for me, this is because
depending on the RPC condition, i might not want to open a new window. 

Alexander Murauski

unread,
Apr 11, 2013, 1:49:30 AM4/11/13
to google-we...@googlegroups.com, Google Web Toolkit
This is how to do it without native JavaScript:

First, create an empty window with the name "mySiperPuperTarget". This must be called synchronously i.e. not from any callback:

Window.open("", "mySuperPuperTarget", "");

Now, you can use the "mySuperPuperTarget" as a target name for your form and submit the from:

FormElement.as(form.getElement()).setTarget("mySuperPuperTarget");

The result of the submission will go to the new window. Since the new window is open in a sync call, there will be no popup blocker triggered.
Reply all
Reply to author
Forward
0 new messages