Ask a Question
Advertise on boostr.in
Can I pop up a confirmation dialog when the user is closing the window in Safari/Chrome?
n IE and FF, i can attach an event handler to onBeforeUnload, and by passing a string to a property of the event, the user will see a dialog asking him whether he wants to continue with the "unloading" (either closing the window or navigating away).
Safari and Chrome don't support onBeforeUnload, and onUnload seems to be too late. Is there some way to replicate the same functionality in Safari/Chrome?
NOTE: I'm not trying to keep the user hostage. I know this is nagging and un-cool. In fact, my site goes to great lengths to let the user go freely, and have everything in its place when they come back. However, I am hosting other sites inside IFrames, and sometimes these decide to get rid of me and take over the browser, which is what I'm trying to avoid.
Aug 18, 2015
to add a comment.
Your name to display (optional):
Email me at this address if my answer is selected or commented on:
Email me if my answer is selected or commented on
Privacy: Your email address will only be used for sending these notifications.
To avoid this verification in future, please