beforeunload event is sometimes misused to prevent Web pages, including popup ads, from being closed by users. Firefox now ignores the return value of
beforeunload event handlers and forces page navigation without showing the confirmation dialog, unless the user has interacted with the page by clicking, touching, scrolling or typing on the elements.
There is also a plan to disallow all
beforeunload dialogs by default, therefore Web developers are encouraged to avoid using this type of events to confirm page navigation. Web pages and apps can improve user experience while preventing dataloss by saving draft state locally with the Web Storage API or IndexedDB API, or remotely with Ajax techniques.
Update: The initial draft of this document was misleading. The
beforeunload event itself will still be fired even if the user has not interacted with the page.