cannot use onunload(). As it is called even when i refresh my page.
Main Topics
Browse All Topicswant 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 ..!!!
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
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('thanksForVisi
<a href="nextpage.htm" onClick="closing=false">Cl
</body>
<html>
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.
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.
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
Business Accounts
Answer for Membership
by: testnPosted on 2003-03-20 at 21:00:24ID: 8178945
You can use onUnload.....
utServlet" ,"LogoutWi n", "toolbar=no,location=no,di rectories= no,status= yes,menuba r=no,scrol lbars=yes, resizable= yes,width= 500,height =150");
function forceLogoff(){
window.open("/servlet/Logo
}
and put this in yout body tag
<BODY onUnload="forceLogoff()">
It will pop up a logoff page.