Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 15108
  • Last Modified:

How to catch the browser close event to delete session - Problem while designing portal using JSF...

Hi all,

I am designing a portal using JSF. It has a user login for which I create a session.
I delete the session if the user clicks on logout. I also want the session to be
deleted when the user closes the browser window. How can I catch the event of
closing the browser??
I thought of using onunload() function but it is specified in some forums that
function specified for onUnload() will be executed either if we refresh the page or
if we close the browser window.

So this might not work for me. Please help me in figuring out a better option.

Thanks,
0
m_razesh
Asked:
m_razesh
1 Solution
 
aaaaaaCommented:
<script>
window.onbeforeunload =
  function(){
    if((window.event.clientX<0) || (window.event.clientY<0)){
        deleteSession();
    }
  }

function deleteSession() {
  //put your code here
}
</script>
0
 
m_razeshAuthor Commented:
Hi,

Thanks a lot for the reply.
But this code is not working in the case of Mozilla.

I have another quick question:
How to call the JSF backing bean method from the JavaScript? Is there any way to do that??

Thanks again.
Rajesh
0
 
bing031398Commented:
You can create a JSF form and call submit from javascript.
0
 
udaybhaskertCommented:
Can you provide a solution for the initial question? The above javascript solution will not work in mozilla. So i need something to work in Mozila. Can you help me on that.

Thanks & Regards
Uday
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now