It's not a secret anymore!
The moose likes HTML, CSS and JavaScript and the fly likes Control browser close event Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Control browser close event" Watch "Control browser close event" New topic

Control browser close event

Gavi Raaghav
Ranch Hand

Joined: Apr 28, 2005
Posts: 82
When the user tries to close the browser i need to present him with a confirm dialog box of OK/Cancel. Clicking on OK will close the browser and clicking on Cancel will keep the user on the same screen.
How to achieve this using Javascript.
onUnload() calls the function but whatever be the user action the browser closes.
Any pointers will be highly appreciated.
Eric Pascarello

Joined: Nov 08, 2001
Posts: 15385
only way to do it is IE only and that is the onbeforeunload event handler. There is not other way to capture the close, you have to realize that the back button, refresh button, links, and closing the browser fire the same event, hence why it basically is impossible to determine what happened.

I agree. Here's the link:
subject: Control browser close event
It's not a secret anymore!