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

I have a binding to the beforeUnload event. If I try to click a link, reload or close a tab or navigator, the application will ask for confirmation before leaving. This is the desired behavior.

But if you press the back button or the back space outside the input, there will be no confirmation.

At the beginning of html:

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

And I use Gwt PlaceHistoryMapper.

What am I missing? Where did I forget to see?

Thanks!

+1
gwt onbeforeunload
source share
1 answer

As long as you stay in your application, because it is a one-page application, it is by definition not unloaded, so there is no beforeunload event.

When using places, the equivalent is a PlaceChangeRequestEvent sent by PlaceController to the EventBus . This event is also dispatched to BTW beforeunload and is the basis for processing mayStop() in actions.

Outside of GWT in the JS world, the equivalent will be hashchange and / or popstate , depending on your implementation of PlaceHistoryHandler.Historian ( History.newItem() used by default, so it will hashchange ).

+2
source share

All Articles