Reputation: 31
Starting from Chrome V80, few events like beforeunload, unload etc are getting deprecated. How would we handle such existing events further in JavaScript?
My requirement is to alert when user tries to refresh / reload the page (F5 or ctrl+r) or browser back button, I need to alert and on confirmation, I need to reload or move back. This is in JSF2.2
But the behavior should not effect the functioning in other browsers.
Can someone please help me with this
Upvotes: 3
Views: 1519
Reputation: 5566
The beforeunload
event will still be usable. What's being changed is the ability to perform sync XHR during page dismissal. The real harmful thing which will be deprecated in the long term is synchronous XHR, since it hurts the user experience. You'll still be able to make use of beforeunload
. Getting Rid of Synchronous XHRs specifically mentions this:
Note: We expect to remove support for synchronous use of XMLHTTPRequest() during page unloads in Chrome in version 80, scheduled to ship early in 2020.
There's also information about this specific change in Chrome Platform Status: Disallow sync XHR in page dismissal. There's more information about Chrome 80 in Deprecations and removals in Chrome 80:
Chrome now disallows synchronous calls to
XMLHTTPRequest()
during page dismissal when the page is being navigated away from or is closed by the user. This applies tobeforeunload
,unload
,pagehide
, andvisibilitychange
.To ensure that data is sent to the server when a page unloads, we recommend
sendBeacon()
orFetch
keep-alive
. For now, enterprise users can use theAllowSyncXHRInPageDismissal
policy flag and developers can use the origin trial flagallow-sync-xhr-in-page-dismissal
to allow synchronous XHR requests during page unload. This is a temporary "opt-out" measure, and we expect to remove this flag in Chrome 82.
Note that popups during page dismissal will also be disallowed:
Pages may no longer use
window.open()
to open a new page during unload. The Chrome popup blocker already prohibited this, but now it is prohibited whether or not the popup blocker is enabled.
Upvotes: 1