GWT Window.ClosingHandler捕获所需的url

时间:2016-03-22 11:24:52

标签: javascript java gwt browser

有没有办法只在需要时触发Window.ClosingHandler? 在我的入口点内,我添加了以下代码,以便弹出一个告诉客户他是否点击了他将从页面中获取的外部链接。

public static void addWindowClosingHandler(){
    Window.addWindowClosingHandler(new Window.ClosingHandler() {
        public void onWindowClosing(Window.ClosingEvent closingEvent) {
            closingEvent.setMessage("Are you sure you want to proceed?");
        }
    });
}

即使我尝试从我的网页下载内容,问题仍然存在。然后,我需要了解被调用页面是否在站点之外,或者所需页面是否在内部。 有没有办法了解哪个是登录页面?

2 个答案:

答案 0 :(得分:0)

这取决于您尝试下载文件的方式。如果您只是打开一个新窗口来下载文件,它将帮助您避免触发窗口关闭处理程序。

    Button downloadBtn = new Button("Download File");
    downloadBtn.addClickHandler(new ClickHandler() {

        @Override
        public void onClick(ClickEvent event) {
            Window.open("http://urlforfiledownload", "download", "");
        }
    });

答案 1 :(得分:0)

最后我找到了另一个合适的解决方案,即使我最终可能会使用" _blank"解决方案由@Ajax提供。

在此链接中,https://groups.google.com/forum/embed/#!topic/google-web-toolkit/Y9hnPFtySuU描述了使用iframe下载文档的另一种方式。步骤应该是:

1)在活动中包含一个iframe,您知道它将被解雇下载操作。

2)按下下载按钮,只需将网址提供给带有空白目标的iframe。

除了浏览器决定打开框架内的内容而不是下载内容之外,这将是一个很好的解决方案。在这种情况下,它将显示为一个错误。因此我可能会接受" _blank"解决方案是最好的解决方案。