File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Control browser close event" Watch "Control browser close event" New topic
Author

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
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
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.

Eric
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Control browser close event