how can i get a prompt on url change

百般思念 提交于 2019-12-31 04:35:32

问题


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..


回答1:


Try Window#ClosingEvent

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:

  • GWT back button browser
  • Best way to detect browser closing/navigation to other page and do logout

Snapshot:




回答2:


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());


来源:https://stackoverflow.com/questions/23225387/how-can-i-get-a-prompt-on-url-change

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!