aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Session destroy on window close Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Session destroy on window close" Watch "Session destroy on window close" New topic
Author

Session destroy on window close

Rizwan Qadri
Ranch Hand

Joined: May 28, 2007
Posts: 40
Hi,

I want to destroy the session by closing window. and I dont want refresh to work also . For that i have written code . But Its running on IE 6 but not on IE 7.
Please help.


<html>
<script>
function doUnload()
{
alert("doUnload");
if (window.event.clientX < 0 && window.event.clientY < 0)
{
alert("Window is closing...");
}
}
</script>
<body onunload="doUnload()">

</body>
</html>


Thanks,

Rizwan
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Rizwan Qadri wrote:Hi,
But Its running on IE 6 but not on IE 7.


Did you allow IE to run scripts? (you know, that annoying yellow bar..?)

As a sidenote, you shouldn't rely on onunload, the user might have disabled JS or he could kill IE's process using the task manager, in neither case would your handler be called!


OCJP 6 (93%)
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60082
    
  65

The only deterministic way to do this is to rely upon the session time-out.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Rizwan Qadri
Ranch Hand

Joined: May 28, 2007
Posts: 40
But the question remains that why it is running in IE 6 but not in IE 7?
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Rizwan, the question remains: is JS enabled in IE7..?
Rizwan Qadri
Ranch Hand

Joined: May 28, 2007
Posts: 40
Ya, JS is enabled in IE7
Lorand Komaromi
Ranch Hand

Joined: Oct 08, 2009
Posts: 276
Try with || instead of &&! And good luck with making it work in other browsers!

(Btw, how is your problem related to JSP..?)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Session destroy on window close
 
Similar Threads
How to pass values from one the main page to a iframe
Accessing JavaMethod from javascript
How to capture close[X] function in javascript?
Remove the session attribute while closing the child window
How to Destroy a Session when the user close the browser