在 gwt 中提示用户退格和浏览器后退按钮 [英] prompt user on backspace and browser backbutton in gwt

查看:13
本文介绍了在 gwt 中提示用户退格和浏览器后退按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从一个类导航到另一个创建的历史时,我有两个类.现在,我想通过确认用户是否想要离开页面来提示用户.直到现在,我尝试在 gwt 中使用 Window.closureHandler() 但它的不适用于退格按钮和浏览器后退按钮,它仅适用于关闭整个浏览器或使用交叉的特定页面.它也在重新加载.

I have two classes when navigating from one class to another created history. Now, I want to prompt the user by a confirm whether user wants to leave the page or not.Till now , I tried using Window.closingHandler() in gwt but its not working for backspace button and browser back button its only working on closing the entire browser or that particular page using cross. Its also working on reload.

我也尝试过 Javascript,它使用 onbeforeunload() 完美运行.

I have also tried on Javascript and it worked perfect using onbeforeunload().

这是我使用的代码.

JAVASCRIPT:

JAVASCRIPT:

window.onbeforeunload = function () {
  return "Are you sure you wish to leave this delightful page?";
}

以及 gwt 中的其他代码:

And the other code in gwt:

Window.addWindowClosingHandler(new Window.ClosingHandler() {
    public void onWindowClosing(ClosingEvent event) {
        event.setMessage("Do you wanna close?");
        System.out.println("Closing...");
    }
});

我希望它在 gwt 中完成.

I want it to be done in gwt.

推荐答案

我在 JSNI 中得到了这个,但它在浏览器后退按钮中也不起作用..

I have got this in JSNI, But its also not working in browser back button..

public native void call()/*-{

    $wnd.onkeypress = GetChar;

     function GetChar (event)
     {
        var key = event.keyCode;

        var bb = event.target.nodeName;

             if(key==8 && bb=="BODY")
                {
                    var x= window.confirm("Are you sureyou want to leave the page");

                    if (x==true)
                            {
                                window.history.back();
                            }
                    else if(x==false)
                            {

                                return false;
                            }
                }
        }                   
}-*/;

这篇关于在 gwt 中提示用户退格和浏览器后退按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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