Window.open not working on Chrome 5 ( GWT 2.0.4 )

976 views
Skip to first unread message

hermis

unread,
Aug 26, 2010, 11:08:11 AM8/26/10
to Google Web Toolkit
Hello all,

I can't seem to get Chrome to open a new window using the
Window.open() function.

It seems to work fine if the function is called from a click handler,
but not when called directly.

Using Firefox and Internet Explorer the following code launches a
window on load and a new window each time
the button is pressed.

public void onModuleLoad()
{
Window.open("http://www.google.com", "_blank", "");
Window.alert("Opened window");

Button btn = new Button("Launch Window!");
btn.addClickHandler( new ClickHandler()
{

@Override
public void onClick(ClickEvent event)
{
Window.open("http://www.google.com", "_blank", "");
Window.alert("Opened window");
}
});

RootPanel.get().add( btn );
}


In Chrome, a window is not launched on load, however when the click
event occurs, it works fine.

hermis

unread,
Sep 1, 2010, 6:06:04 AM9/1/10
to Google Web Toolkit
Whoops... apparently Chrome's pop-up blocker was kicking in :/

Jason Essington

unread,
Sep 1, 2010, 12:08:47 PM9/1/10
to google-we...@googlegroups.com
That's correct. 

You only ever want to open a window as a direct result of a user action (onClick, keypress, etc) otherwise you may run afoul of any popup blocker.

This means that you cannot open a window in a callback. That is asynchronous that is not a direct result of a user action. If you need to open a window to display a generated document (PDF for instance) then you'll have to open the window when the user clicks some button, send the request to generate the document, then manipulate the window.
 

-jason


--
You received this message because you are subscribed to the Google Groups "Google Web Toolkit" group.
To post to this group, send email to google-we...@googlegroups.com.
To unsubscribe from this group, send email to google-web-tool...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


Reply all
Reply to author
Forward
0 new messages