GWT在新标签中打开页面 [英] GWT open page in a new tab

查看:118
本文介绍了GWT在新标签中打开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发GWT应用程序,并使用

  com.google.gwt.user.client.Window.open(pageUrl ,_blank,); 

打开新页面。当它被调用时,它会在新标签页中打开,例如,在按钮点击后直接打开。
但是我决定在打开新页面之前在服务器上做一些验证,并将调用上面提到的方法放到

  public void onSuccess(Object response){
}

它开始打开页面在新窗口中,而不是新标签(这仅适用于Chrome,其他浏览器仍然会在新标签中打开它)。



任何人都可以帮助我吗?






我建立了一个小例子来说明问题:

  button.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event){
Window.open(http://www.google.com/,_blank ,);
MySampleApplicationServiceAsync serviceAsync = GWT.create(MySampleApplicationService.class);
serviceAsync.getMessage(Hello,Server!,new AsyncCallback(){

public void onFailure(Throwable caught){
Window.alert(ER ROR);
}

public void onSuccess(Object result){
Window.open(http://www.bing.com/,_blank,);
}
}
);
}
});




  • Firefox(3.6.8)在新标签中打开两页。 / li>
  • Chrome(6.0)在新标签页中打开google.com,在新窗口中打开bing.com
  • Opera(10.10)

  • IE(8.0)可在新窗口中打开。






我将igorbel的答案标记为唯一正确的因子,我没有找到任何适当的方式来指定所有情况下的相同行为。





解决方案

我不确定你将能够以你想要的方式来控制它。问题在于浏览器可以决定何时打开窗口以及何时打开制表符。例如,firefox可以选择:改为在新标签中打开新窗口。不要忘记那些不支持标签的浏览器(是的,这些浏览器依然存在)。

由于这是用户体验的一个有问题的方面,我的建议将重新考虑你的设计。对于您的应用程序来说,打开一个新选项卡并打开一个新窗口是否真的非常重要?


I am developing GWT application and I use

com.google.gwt.user.client.Window.open(pageUrl, "_blank", "");

to open new page. And it opens in a new tab when called, for example, directly after button click. But I decided to do some validations on server before opening new page and placed the call to the mentioned above method to the

public void onSuccess(Object response) {
}

And it starts to open pages in new window instead of new tab (this is true only for Chrome, other browsers still open it in a new tab).

Can anybody help me?


I built a small example to illustrate the issue:

    button.addClickHandler(new ClickHandler() {
        public void onClick(ClickEvent event) {
            Window.open("http://www.google.com/", "_blank", "");
            MySampleApplicationServiceAsync serviceAsync = GWT.create(MySampleApplicationService.class);
            serviceAsync.getMessage("Hello, Server!", new AsyncCallback() {

                public void onFailure(Throwable caught) {
                    Window.alert("ERROR");
                }

                public void onSuccess(Object result) {
                    Window.open("http://www.bing.com/", "_blank", "");
                }
            }
            );
        }
    });

  • Firefox(3.6.8) opens both pages in new tabs.
  • Chrome(6.0) opens "google.com" in new tab and "bing.com" in new window
  • Opera(10.10) opens in new tabs.
  • IE(8.0) opens both in new Windows.

I marked igorbel 's answer as the only correct cos I haven't found any proper way to specify the same behaviour in all situations.


解决方案

I am not sure you are going to be able to control this the way you want. The problem is that browsers can decide when to open windows and when to open tabs. For example, firefox has the option: "Open new windows in new tabs instead". And don't forget the browsers that don't support tabs (yes, those do still exist).

Since this is such a problematic aspect of the user experience, my recommendation would be to reconsider your design. Is it really that important for you application to differentiate between opening a new tab and opening a new window?

这篇关于GWT在新标签中打开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆