Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Anand Sivathanu
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!