This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes how to invoke a function in javascript on closing the browser 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 "how to invoke a function in javascript on closing the browser window" Watch "how to invoke a function in javascript on closing the browser window" New topic
Author

how to invoke a function in javascript on closing the browser window

Anand Sivathanu
Ranch Hand

Joined: Jun 25, 2010
Posts: 76
Hi All,

I would like to know to invoke a function in JavaScript on closing the browser window.I am trying to

invalidate the user's session in JSP when the user unfortunately closes the browser window.

I have tried the following steps

function UnLoad() {
window.alert("on closing");

}

window.onunload=unLoad;

<body onUnload='javascript:UnLoad();'>


but its not working.

Please help me in this issue.

Regards,
Anand Sivathanu
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 63211
    
  69

This has been discussed many many times before in this forum. Please SearchFirst.

The result is always the same: you cannot be reliably informed when the browser is closed. You must rely upon the session timeout to allow orphaned sessions to be reclaimed.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: how to invoke a function in javascript on closing the browser window
 
jQuery in Action, 3rd edition