?
Solved

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

Posted on 2006-07-21
4
Medium Priority
?
15,058 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 1500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

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

Question has a verified solution.

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

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
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…
Suggested Courses

599 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