Solved

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

Posted on 2006-07-21
4
14,769 Views
Last Modified: 2012-04-13
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
Comment
Question by:m_razesh
4 Comments
 
LVL 4

Accepted Solution

by:
aaaaaa earned 500 total points
ID: 17162598
<script>
window.onbeforeunload =
  function(){
    if((window.event.clientX<0) || (window.event.clientY<0)){
        deleteSession();
    }
  }

function deleteSession() {
  //put your code here
}
</script>
0
 

Author Comment

by:m_razesh
ID: 17170579
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
 

Expert Comment

by:bing031398
ID: 21038851
You can create a JSF form and call submit from javascript.
0
 

Expert Comment

by:udaybhaskert
ID: 37841924
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

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now