Why the OnBeforeUnload doesn't intercept the back button in my GWT app?

时光总嘲笑我的痴心妄想 提交于 2019-12-02 11:35:47

问题


I have a hook on the beforeUnload event. If i try to click on a link, reload or close the tab or the navigator, the app ask for confirmation before leaving. That's the desired behavior.

But if click on the back button or the backspace outside an input, no confirmation.

At the beginning of the html :

window.onbeforeunload = function() {
 if (confirmEnabled)
    return "";
}

And i use the Gwt PlaceHistoryMapper.

What did i miss ? Where did i forgot to look ?

Thanks !


回答1:


As long as you stay within your app, because it's a single-page app, it doesn't by definition unload, so there's no beforeunload event.

When using Places, the equivalent is the PlaceChangeRequestEvent dispatched by the PlaceController on the EventBus. This event is also dispatched in beforeunload BTW, and is the basis for the mayStop() handling in Activities.

Outside GWT, in the JS world, an equivalent would be hashchange and/or popstate, depending on your PlaceHistoryHandler.Historian implementation (the default one uses History.newItem(), so that would be hashchange).



来源:https://stackoverflow.com/questions/13358476/why-the-onbeforeunload-doesnt-intercept-the-back-button-in-my-gwt-app

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