How can I handle the close event of a browser to trigger a logout?
相关问题
- #{facesContext} EL expression not resolved at runt
- jsp caching tag library
- JSP template implementation (Composite View Patter
- how to add a list of string into json object in js
- Two dimensional arraylist with c:foreach jstl tag
相关文章
- jsp里面的画布功能,为什么会出错?求大佬找下问题
- JSP String formatting Truncate
- Forward request from servlet to jsp
- Comparing string and boolean in Expression languag
- Passing a Java object value in Custom JSP tag
- Passing a enum value as a tag attribute in JSP
- Application Error: AccessControlException
- MySQL driver problem in my dynamic web project (JP
You're looking for the onunload:
There are 2 problems with this:
I recommend using a different approach.
I've searched for a consistent solution to this problem some time ago, and my decision was to handle the situation without believing the browser or the user.
You can't for sure know if a user is leaving your page and when, and even if you use 'onunload', you may not get the event before the browser closes or leaves your page. And browser crashes won't give you any kind of signal, so believing you know the user is still viewing you page and may take any further action is flawed.
The best you can do about logging out an user is put a fitting session timeout, and if you need further control, you may try adding AJAX calls on critical pages with 'I'm alive' signals, and then logging out users that are not responding anymore (that would require AJAX/JS enabled browser and may exclude potential users).
You have to go with session timeout. Since you have tagged your question JSP, I think it is a java web application that you are talking about.
You generally have a session timeout listener, and have your "logout" code in the listener.
Generally don't rely on client side events: a browser/system crash, shutdown without closing the browser etc will not trigger the events.