Wednesday, September 1, 2010

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

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


On Sep 1, 2010, at 4:06 AM, hermis wrote:

Whoops... apparently Chrome's pop-up blocker was kicking in :/

On 26 Aug, 16:08, hermis <ermis.h...@gmail.com> wrote:
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.

--
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-web-toolkit@googlegroups.com.
To unsubscribe from this group, send email to google-web-toolkit+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-web-toolkit?hl=en.


No comments:

Post a Comment