jsp - Alternative for JavaScript onUnload - Stack Overflow

there is an alternative to the Javascript onUnload? I use JSP Jakarta Struts framework with a Servlets.

there is an alternative to the Javascript onUnload? I use JSP Jakarta Struts framework with a Servlets.

I must know, when is window closing, because not everyone clicks on Logout button.
How do you handle it in your applications?

there is an alternative to the Javascript onUnload? I use JSP Jakarta Struts framework with a Servlets.

I must know, when is window closing, because not everyone clicks on Logout button.
How do you handle it in your applications?

Share asked Aug 29, 2009 at 13:41 wokenawokena 1,3794 gold badges15 silver badges17 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 6

Generally speaking, it's impossible to determine conclusively whether a visitor is still "using" (or even looking at) your page. Once the browser has downloaded the page, it's no longer in contact with the server at all, so the page could stay open for a few seconds or a few years and the server would have no idea.

The unload event is certainly a helpful clue, since it usually fires when the page is unloaded. It's not at all reliable, however. There are plenty of situations where it won't fire, and plenty more where even though it does fire your server will remain unaware of it.

For example: the browser (or even the operating system) could crash, or the power could go out. A visitor using Wi-Fi could get disconnected, or could carry her iPhone into a tunnel while using your site.

The standard workaround for this — which we all readily admit is terrible — is to let the visitor's session timeout. Even on high-stakes banking websites, you'll find that if you walk away from your puter for four minutes and e back you still have access, but if you walk away for five you're locked out.

This setup certainly finds a lot of false positives: cases where a visitor was still using your page without interacting with it, and therefore is inconvenienced by the timeout. It also allows false negatives: cases where the real visitor has walked away, and a malicious user takes over within the timeout period.

The only major addition to this scheme we've seen lately is exploitation of JavaScript to visibly log the user out after the timeout period. Again, we see this on banking websites: leave the page open for too long and when you e back all you'll see is a login screen. (Of course, this too depends on JavaScript and so is still fallible.)

Unfortunately, since HTTP is a stateless protocol, we'll never be able to know for sure what's going on in the browser (especially if JavaScript is off), so cheap workarounds are really all we can use.

You should be aware that Opera does not execute onUnload as you would suspect. And you should not rely on javascript to see if users close windows.

I rely on the servlet session timeout to handle the logout automatically. You can register a handler for when the session times out to cover any credential cleanup you need to do. A good example is given here:

http://www.xyzws./Servletfaq/when-do-i-use-httpsessionlistener/7

There is no guarantee from the client side that the user will always confirm that they have finished using your site.

I use the onbeforeunload. See the documentation

After testing it seems to work on Firefox, Chrome, IE11 and Edge.

I didn't test any other browser.(patibility list is here)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745097610a4611075.html

相关推荐

  • jsp - Alternative for JavaScript onUnload - Stack Overflow

    there is an alternative to the Javascript onUnload? I use JSP Jakarta Struts framework with a Servlets.

    8小时前
    10

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信