GWT back button browser

后端 未结 5 818
长情又很酷
长情又很酷 2021-01-18 11:08

For example current page is www.google.com. But I typed a different website address in address bar and clicked. This site has fully GWT code.

But I like to back to t

相关标签:
5条回答
  • 2021-01-18 11:56

    try this it will work

    Event.addNativePreviewHandler(new Event.NativePreviewHandler() {
    
            @Override
            public void onPreviewNativeEvent(final NativePreviewEvent event) {
                if (event.getTypeInt() == Event.ONKEYDOWN) {
                    if (event.getNativeEvent().getKeyCode() == KeyCodes.KEY_BACKSPACE) {
                        Element element = Element.as(event.getNativeEvent().getEventTarget());
    
                        String tagName = element.getTagName();
    
                        System.out.println(tagName);
    
                        // Add checks for other input controls
                        if (!tagName.equalsIgnoreCase("INPUT") 
                                     && !tagName.equalsIgnoreCase("TEXTAREA")) {
    
                            boolean result = Window.confirm("Are you sure?");
                            if (!result) {
                                event.cancel();
                            }
                        }
                    }
                }
            }
        });
    
    0 讨论(0)
  • 2021-01-18 11:58

    +1 to Igor and Alex. Here's some code you can use, if you want to use the ClosingHandler:

        Window.addWindowClosingHandler(new Window.ClosingHandler() {
    
            @Override
            public void onWindowClosing(final ClosingEvent event) {
                event.setMessage("Don't you think my site is awesome?");
            }
        });
    

    Some info from the Javadoc of ClosingHandler.onWindowClosing():

     /* Fired just before the browser window closes or navigates to a different
      * site. No user-interface may be displayed during shutdown. */
    
    0 讨论(0)
  • 2021-01-18 12:00

    you also can use this native code

     public native void call()/*-{
    
        $wnd.onkeydown = GetChar;
    
         function GetChar (event)
         {
            var key = event.keyCode;
    
            var bb = event.target.nodeName;
    
            if(key==8 && bb=="BODY")//checking keyCode of key for backspace
                    {
                        var x= window.confirm("Are you sureyou want to leave the page");
    
                        if (x==true)
                                {
                                    window.history.back();
                                }
                        else if(x==false)
                                {
    
                                    return false;
                                }
                    }
            }                   
    }-*/;
    
    0 讨论(0)
  • 2021-01-18 12:01

    You can implement the HistoryListener interface: your class's method onHistoryChanged will be called (with a String token) on every click to the back and forward buttons. You can then interact with the History class, which has e.g. a back() static method to "go back". However, I'm not entirely sure if it goes back all the way to before GWT started (but it's sure worth trying;-).

    0 讨论(0)
  • 2021-01-18 12:11

    There's Window.ClosingEvent:

    Fired just before the browser window closes or navigates to a different site.

    The other option is History.addValueChangeHandler, which listens for changes in the browser's history stack (see the docs for more info).

    0 讨论(0)
提交回复
热议问题