1

So I want to ask users to confirm that the want to leave the page before the browser is closed. I don't have problem showing the user message box when he is navigating away from the page, only when he's closing the window. This doesn't work for me:

PLATFORM.global.addEventListener("beforeunload", this._beforeUnloadEventHandler);

And this answer only helps with navigating away.

Community
  • 1
  • 1
Marek M.
  • 3,799
  • 9
  • 43
  • 93

2 Answers2

0

Does this work?

PLATFORM.global.addEventListener("beforeunload", () => this._beforeUnloadEventHandler());
Ashley Grant
  • 10,879
  • 24
  • 36
0

Not sure how jquery event system works compared to PLATFORM.global.addEventListener but this is what I use.

$(window).on('beforeunload', () => {
  if (this.dirty) {
    return 'Really leave?'; // return a string to ask the user. You can't stop it in any other way.
  }
});
Leonidas A
  • 329
  • 2
  • 11