We have SAPUI5 Shell placed at a div inside an index.xhtml page. When user modifies the data in our application, user can perform 3 types of action for navigating away from the application:
- Press the cancel button in our application
- Type some other URL in the browser address bar
- Press the back-button in the browser bar.
Our SAPUI5/Openui5 application works with the route concept (sap.ui.core.routing.Router) and hence the application has 'HASH URL'.
For 1 & 2, we made the following change and it works (based on Mozilla recommendation)
window.onbeforeunload = function(e) {
var dialogText = 'Dialog text here';
e.returnValue = dialogText;
return dialogText;
};
Mozilla Recommendation - https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload
But for pt.3 - when user presses BACK BUTTON, the HASH URL changes. Based on other discussion on Stackoverflow, playing around with browser history or disabling the browser back button is not working with Browser/Web World.
Is there a way to do the following when browser back button is pressed:
- Show Popup giving user an option to Stay or Leave (informing changes in page will be lost)
- If user chooses to stay, then the URL remains including the 'HASH URL' part.