i am new in gwt . I want when a user press back button he get a alert that page will we refresh .mostly we see during typing on loose focus if user press back button his page get refresh and all value goes wash. how can we achieve this..
Asked
Active
Viewed 333 times
2 Answers
0
Window.addWindowClosingHandler(new ClosingHandler() {
@Override
public void onWindowClosing(ClosingEvent event) {
event.setMessage("Message");
}
});
Please have a look at promt user on backspace and browser backbutton in gwt where I have mentioned other ways also.
For more info have a look at below posts:
Snapshot:
-
thanks it work but when I press back space it is calling previous class i need to prompt user on back space..please help – Apr 22 '14 at 17:20
-
OK Let me share you some links. – Braj Apr 22 '14 at 17:24
-
Please have a look at [How can I prevent the backspace key from navigating back?](http://stackoverflow.com/questions/1495219/how-can-i-prevent-the-backspace-key-from-navigating-back?answertab=votes#tab-top). – Braj Apr 22 '14 at 17:27
-
Try to debug it. It should work. There are lots of answers. try other one also. – Braj Apr 22 '14 at 17:36
-
OK Let me try to understand what happens if you press backspace in textfield? – Braj Apr 22 '14 at 18:15
-
I am using history class . when i press back space its history token goes change . how can i prompt user when history change – Apr 23 '14 at 05:38
-
Please read it carefully. use [History.addValueChangeHandler()](http://www.gwtproject.org/javadoc/latest/com/google/gwt/user/client/History.html) which listens for changes in the browser's history. – Braj Apr 23 '14 at 05:43
-
I used history change listener but i am getting prompt both time . once a new history item create and second value change of history on back space – Apr 23 '14 at 07:01
-
and i have to create value change handler for every class – Apr 23 '14 at 07:02
0
this will work but result is same
RootPanel.get().addDomHandler(new KeyUpHandler() {
@Override
public void onKeyUp(KeyUpEvent event) {
if (event.getNativeKeyCode() == KeyCodes.KEY_BACKSPACE) {
event.preventDefault();
}
}
}, KeyUpEvent.getType());