?
Solved

Calling Logout on closing my browser window

Posted on 2003-03-20
8
Medium Priority
?
784 Views
Last Modified: 2012-08-14
want to call my logout servlet if someone hits browser close button.
I tried all javascript combinations with onUnLoad() window.close() etc but nothing wrks as these events gets fired even on refresh and changing the locationof the url.

I was giving up when i saw the implementation in citibanks website. If anyone has account with citibank then u can check it out.
I tried to look into the view source but coulnd't make out anything..

any ideas will be highly appreciated ..!!!
0
Comment
Question by:agsingh
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 18

Expert Comment

by:testn
ID: 8178945
You can use onUnload.....

function forceLogoff(){
window.open("/servlet/LogoutServlet","LogoutWin", "toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,width=500,height=150");
}

and put this in yout body tag
<BODY onUnload="forceLogoff()">

It will pop up a logoff page.

0
 

Author Comment

by:agsingh
ID: 8180673
cannot use onunload(). As it is called even when i refresh my page.
0
 
LVL 1

Expert Comment

by:Jitu
ID: 8201618
Infact onUnload will be called even when u r going from one page to another !!

Here is a guess :
I haven't used Citibank website, but my guess is that it actually does not log you out when you close the window. Instead when u try returning to the website, it recognises that you are not using a valid previous page to come to the requested page, and it logs you out at that point.

In a typical MVC model :
1. The only way to go from one page to another is via a Controller Servlet.
2. Any direct access to a page (jsp) is denied. Any attempt for direct access, sends the user to login page.

===

In any case , here is a not-very-nice way to achieve what you want via javascript, assuming there was one link on my page. This gives u a general idea :

<html>
<body onLoad="closing=true" onUnload="if (closing) window.open('thanksForVisiting.html','newwin');">

<a href="nextpage.htm" onClick="closing=false">Click to go to another page..</a>

</body>
<html>


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:agsingh
ID: 8212504
Let me reframe my question. I want to do some action when i am closing my browser window(like open a win)
The code that u have written works fine, but the only problem is as i mentioned earlier when i try to refresh my page same is executed. How can i prevent this...!!!
0
 
LVL 1

Accepted Solution

by:
Jitu earned 200 total points
ID: 8215433
If u ask me, user should indeed get logged out if he tries to refresh the page. This is the behavior in citibank site too... infact this is what they have done :

1. Removed all toolbar buttons from the window. So user cannot hit refresh.
2. Even the refresh available via right click popup menu is disabled i think.

ICICI Bank logs you out if you hit refresh, try to move across the website by clickin Browser Back/Forward buttons etc. The only valid way to move across pages for them is to hit the Previous/Next etc. buttons and link provided on the pages.
0
 

Expert Comment

by:CleanupPing
ID: 9058567
agsingh:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 15

Expert Comment

by:jimmack
ID: 9730562
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

Accept Jitu's comment as answer.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jimmack
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Suggested Courses
Course of the Month10 days, 11 hours left to enroll

764 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