Skip to Content
0

Browser back Button handle

Nov 24, 2017 at 01:53 PM

88

avatar image
Former Member

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);
  }
}
10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
Irfan Gokak Nov 26, 2017 at 02:06 PM
0

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
    }
}
Show 2 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi,
it works on all the buttons even the menu of the application, i want a function that handle only the browser back button.

thanks,
Bilel

0
Former Member

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);
  }
}
0
Irfan Gokak Nov 26, 2017 at 02:31 PM
0

Hi,

Below code tested in Chrome browser. Please check.

window.onbeforeunload = function() { return "You work will be lost."; };
Show 1 Share
10 |10000 characters needed characters left characters exceeded
Former Member

it works only when the refresh button was clicked.

0