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 User closing browser 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 "User closing browser" Watch "User closing browser" New topic
Author

User closing browser

Joe Busch
Greenhorn

Joined: Jan 07, 2005
Posts: 12
Is there a simple way to have the browser send a Logout request if the user should close the browser window?

Thanks,
Joe
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

There is no reliable way to do this.

This is a very common question, search through this forum for previous conversations on just this topic.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
One solution was to use a pop up window, but pop up blockers blocked this idea. You basically have to rely the session to timeout on the server and handle it that way. PLUS there is no real way to detect a back button verus a link verus a refresh verus a close.

OR

make sure to tell your users to log out or they will never be allowed back in!

Eric
Joe Busch
Greenhorn

Joined: Jan 07, 2005
Posts: 12
Thanks for the responses. I was thinking I would have to do it on the server. I was looking at using the onUnload to send a logout to the server, but the only way I could see sending it via the javascript below left me with a taskbar icon that had an error 404:

<script language="JavaScript">
function autoLogout()
{
var iX = window.event.clientX ;
var iY = window.event.clientY ;
if (iX < -1000 && iY < -1000)
{
var winExit = window.open("/hostfolder/Logout.com", "", "height=1, width=1, left=1000, top=1000, toolbar=0, menubar=0, status=0, resize=no");
}
}
</script>
...
<body onUnload="autoLogout();">
...

If you think this has any merit let me know.
Thanks again,
joe
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60057
    
  65

using the onUnload to send a logout to the server


Think for a moment about when onunload is invoked. Is this really what you want to do?

Your best bet is to just rely on the session timeout.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: User closing browser
 
Similar Threads
enforcing to enable javascript
Back button in browser- Expire session
Session handling
User Agent String???
Basic authentication without a secure connection