sajad torkamani

In a nutshell

The beforeunload event is fired when a user is about to leave a webpage. The page is still visible at this point and the navigation away from the page can still be cancelled.

The event is useful for prompting the user to confirm that they want to leave the page when some data they’ve entered is unsaved and will be lost if they navigate away.

Other notes

Sticky activation is required. The user must have interacted with the page for this feature to work.

Links

  • Window: beforeunload event – MDN
Tagged: Web APIs