如何抓住用户离开一个页面并取消它 [英] How to catch user leaving a page and cancelling it

查看:82
本文介绍了如何抓住用户离开一个页面并取消它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户离开GWT应用时,我想打开一个确认对话框,让他们选择留下,即确认(您确定要离开此页面,是,否) 。



我知道如何构建拨号盒。 :)



问题是,如何捕捉用户离开页面的事件以及如何取消它?

Daniel

解决方案

致电 Window.addWindowClosingHandler ,并传递一个回调,该回调调用 setMessage 在Window.ClosingEvent上,如下所示:

  Window.addWindowClosingHandler(new Window.ClosingHandler(){
public void onWindowClosing(Window.ClosingEvent closingEvent){
closingEvent.setMessage(您真的要离开页面吗?);
}
});

(我已经链接到GWT 2.0文档;在这些URL中将2.0更改为1.6看看GWT 1.6 / 1.7文档)。注意这样做,你不必自己创建对话框。

When a user leaves the GWT app, I would like to open a confirm dialog and offer them the choice to stay, i.e. Confirm("are you sure you want to leave this page", "yes", "no").

I know how to build the dialbox. :)

The question is, how to I catch the event of a user leaving the page and how to I cancel it?

Daniel

解决方案

Call Window.addWindowClosingHandler, and pass it a callback that calls setMessage on the Window.ClosingEvent, like so:

Window.addWindowClosingHandler(new Window.ClosingHandler() {
      public void onWindowClosing(Window.ClosingEvent closingEvent) {
        closingEvent.setMessage("Do you really want to leave the page?");
      }
    });

(I've put in links to the GWT 2.0 docs; change the 2.0 to 1.6 in those URLs to see the GWT 1.6/1.7 docs.)

Note that doing it this way, you don't have to/don't get to create the dialog box yourself.

这篇关于如何抓住用户离开一个页面并取消它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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