简体   繁体   中英

How can I ask users to confirm before closing the window with Aurelia.js app

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.

这样行吗?

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

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.
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM