Hi folks,
I'm trying to open a modal window when the browser window closes. Is there a way to do this with window events? Thanks.
Hi folks,
I'm trying to open a modal window when the browser window closes. Is there a way to do this with window events? Thanks.
Short answer: no: Most browsers don't let you know when the browser is being closed.
See also:
http://stackoverflow.com/questions/299679/java-servlet-how-to-detect-browser-closing
http://stackoverflow.com/questions/317042/how-capture-event-for-browser-closing-in-web-applications
You can execute whatever you need to with the onunload JavaScript event. I'd probably do a window.open rather than try to create a modal because I think the browser will still close. You could use the onbeforeunload event to show a modal confirming their action if that's what you're hoping to do.