简体   繁体   中英

I need a confirmation pop up on browser close.I am using onbeforeunload event but not working in Firefox also want to restrict pop up on page refresh

I need a confirmation pop up on browser close. I amm using onbeforeunload event but not working in Firefox also the pop up comes whenever the page refreshed which I want to restrict.

window.onbeforeunload = DetectBrowserExit;

function DetectBrowserExit() {
return 'Are you sure to exit';`enter code here`
}

Not all browsers support this feature and with time browsers minimized their support (for example removed custom text support). Reason is that it is used by spam like websites that prevent you from navigating out.

you can see full details here:

https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload

Checkout also the Browser compatibility section in that page. I would definitely suggest NOT to rely on that event and come up with alternatives that fit your website more.

specifically about firefox, see this explanation from the link I shared above:

Note also that various mobile browsers ignore the result of the event (that is, they do not ask the user for confirmation). Firefox has a hidden preference in about:config to do the same. In essence this means the user always confirms that the document may be unloaded.

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