Skip to Content
avatar image
Former Member

Browser back Button handle

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);
  }
}
Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 26, 2017 at 02:06 PM

    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
        }
    }
    Add comment
    10|10000 characters needed characters exceeded

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

    Hi,

    Below code tested in Chrome browser. Please check.

    window.onbeforeunload = function() { return "You work will be lost."; };
    Add comment
    10|10000 characters needed characters exceeded