agsingh
asked on
Calling Logout on closing my browser window
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 ..!!!
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 ..!!!
ASKER
cannot use onunload(). As it is called even when i refresh my page.
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 ting.html' ,'newwin') ;">
<a href="nextpage.htm" onClick="closing=false">Cl ick to go to another page..</a>
</body>
<html>
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>
ASKER
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...!!!
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...!!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
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
function forceLogoff(){
window.open("/servlet/Logo
}
and put this in yout body tag
<BODY onUnload="forceLogoff()">
It will pop up a logoff page.