Solved

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

Posted on 2006-07-21
4
14,732 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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
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…

747 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

13 Experts available now in Live!

Get 1:1 Help Now