GWT Feedback Button

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

But I like to go back to the previous page www.google.com. So I clicked the back button in the browser. But how can I get the back button from the current GWT code. Is it possible to install any event handler on the back panel in the GWT of the current page? One that notifies me that the back button is pressed.

Is there any solution from GWT?

+6
gwt browser-history
source share
5 answers

There Window.ClosingEvent :

Dismissed just before the browser window closes or goes to another site.

Another option is History.addValueChangeHandler , which listens for changes in the browser history stack (see the docs for more information).

+5
source share

+1 to Igor and Alex. Here is the code you can use if you want to use ClosingHandler:

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

Some information from 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. */ 
+5
source share

You can implement the HistoryListener interface: your onHistoryChanged class onHistoryChanged will be called (with a String token) every time you press the back and forward buttons. Then you can interact with the History class, which has, for example, a back() static "return" method. However, I'm not quite sure that it all started before the start of GWT (but it is definitely worth a try -).

+1
source share

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
source share

you can also 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
source share

All Articles