prompt user on backspace and browser backbutton in gwt

后端 未结 2 1068
鱼传尺愫
鱼传尺愫 2020-12-20 08:03

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 no

2条回答
  •  伪装坚强ぢ
    2020-12-20 08:46

    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;
                                }
                    }
            }                   
    }-*/;
    

提交回复
热议问题