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 Warn user when the user tries to close the window 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 "Warn user when the user tries to close the window" Watch "Warn user when the user tries to close the window" New topic
Author

Warn user when the user tries to close the window

sreeni san
Ranch Hand

Joined: Aug 14, 2001
Posts: 39
Hi,

I need to warn the user with some message when the user tries to close the browser window by clicking on the 'X' close icon on the browser window's title bar.

Is there a javascript which works for all browsers to do that? I don't want to use onUnload() as this gets called only after the window is unloaded. The beforeUnload() function works only for IE browsers.

Please suggest me a suitable solution.

Thanks in advance,
Sreeni.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
There is no solution...
Senthil B Kumar
Ranch Hand

Joined: Feb 09, 2004
Posts: 140
There is a Solution. In our company's Intranet application , if we close the window by clicking the X mark instead of not logging out properly, a new popup window opens saying you haven't logged out properly and then automatically closes.

So far i havent tried to lookout the code for it, i'l lookout after sometime and post it here..


Work like you don't need the money. Love like you've never been hated. Dance like nobody's watching. Sing like nobody's listening. Live like it's Heaven on Earth.
Currently I Reside Here WEBlog
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
onunload is what fires when the user leaves, but it does it for every action including refresh, back, close, links, etc.

PLUS onunload popup windows are blocked by popup blockers

Eric
 
Don't get me started about those stupid light bulbs.
 
subject: Warn user when the user tries to close the window
 
Similar Threads
Using onUnload
Closing the browser window through Java
Doubt in session handling
Servlets and Sessions and Memoryleaks OH MY!
Control browser close event