on 11-24-2017 1:53 PM
Hi All,
how can i handle the Browser Back Button in SAPUI 5? I want that when the user clicks on the button "back" of the browser, it is possible to display a popup that alerts that there is some data not saved.
Thank you,
Bilel
Edit (Solution):
document.onmouseover = function() {
//User's mouse is inside the page.
window.innerDocClick = true;
}
document.onmouseleave = function() {
//User's mouse has left the page.
window.innerDocClick = false;
}
window.onhashchange = function() {
if (window.innerDocClick != false) {
window.innerDocClick = false;
} else {
//Browser back button was clicked
me.checkDataModified(true);
}
}
Hi,
Try this function.
window.onhashchange = function() {
if (window.innerDocClick) {
//Your own in-page mechanism triggered the hash change
} else {
//Browser back button was clicked
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I have modified your code and it's worked:
document.onmouseover = function() {
//User's mouse is inside the page.
window.innerDocClick = true;
}
document.onmouseleave = function() {
//User's mouse has left the page.
window.innerDocClick = false;
}
window.onhashchange = function() {
if (window.innerDocClick != false) {
window.innerDocClick = false;
} else {
//Browser back button was clicked
me.checkDataModified(true);
}
}
Hi,
I have added those functions on the init function and now even if I am on another page, the functions are triggered. How can I narrow the impact of those functions ONLY for the page and controller I am setting it up?
Thanks in advance for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
The above solution works only for single page/view applications.
For the 2 or more views application, you can call these functions in the objectpatternmatched method which gets triggered when the pattern matched or onbeforerendering method of the controller. So, it will always triggered on pattern matched.
I have faced the same issue and it got solved.
Thanks,
Soumya
Thanks for coming to SAP Community for answers. Please post your question as a new question here:
https://answers.sap.com/questions/ask.htmlSince you're new in asking questions here, check out our tutorial about asking and answering questions (if you haven't already), as it provides tips for preparing questions more effectively, that draw responses from our members. Please note, that your post here won't be answered.
Hi,
Below code tested in Chrome browser. Please check.
window.onbeforeunload = function() { return "You work will be lost."; };
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
94 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.