简体   繁体   English

浏览器再次关闭问题

[英]Browser close issue again

I've system that tracks users' work hours and workflow is like this:我有跟踪用户工作时间和工作流程的系统是这样的:

If user logs in he/she is in and there are button buttons out/in buttons also log-out that handles out event.如果用户登录,他/她在并且有按钮按钮退出/进入按钮也注销来处理事件。

The problem is when user closes the browser/tab, I cannot handle he or she is out.问题是当用户关闭浏览器/选项卡时,我无法处理他或她不在的情况。 I've read about handling browser/tab close events, but, unfortunately, it's practically impossible.我读过有关处理浏览器/标签关闭事件的文章,但不幸的是,这实际上是不可能的。 My next approach which is not more reliable, with cookies, I save the cookie when page onUnloads when page loads that cookie will be removed, and when user logs in I'll get cookies value which contains users' last activity and update the out time.我的下一个方法不太可靠,使用onUnloads ,我在页面加载时保存 cookie,当页面加载时该 cookie 将被删除,当用户登录时,我将获得 cookies 值,其中包含用户的最后活动并更新退出时间. But drawback is user may come to the site with different browsers/machines which doesn't have proper information about the last activity.但缺点是用户可能会使用不同的浏览器/机器访问该站点,这些浏览器/机器没有关于最后一个活动的正确信息。

I personally would look at the session object.我个人会看 session object。 When that expires you can do whatever you need to do.到期后,您可以做任何您需要做的事情。

What you can do is a javascript call to the server every minute (using the Javscript timer functions as explained here: http://www.w3schools.com/js/js_timing.asp ).您可以做的是每分钟对服务器进行一次 javascript 调用(使用此处解释的 Javscript 计时器功能: http://www.w3schools.com/js/js_timing.asp )。

But I am not sure your approach using the browser is correct.但我不确定您使用浏览器的方法是否正确。 By definition, the browser/server connection is not connected.根据定义,浏览器/服务器连接未连接。 Cookies are a just a way to maintain connectivity because the HTTP protocol do not provide such features. Cookies 只是保持连接的一种方式,因为 HTTP 协议不提供此类功能。

The second point is: you want to keep the track when the user connects from another browser.第二点是:当用户从另一个浏览器连接时,您要保持跟踪。 What about the user uses 2 different browsers in the same time?如果用户同时使用 2 个不同的浏览器呢? How do you detect the user (should he authenticates when the browser opens or can you rely on the IP address)?您如何检测用户(他应该在浏览器打开时进行身份验证,还是您可以依赖 IP 地址)? What I suggest is having a proper application to handle this: not a browser application.我建议有一个适当的应用程序来处理这个问题:而不是浏览器应用程序。 It should be not very complex to write one.写一个应该不是很复杂。

Well, applets and Adobe Flash could be a solution to enhance the capabilities in the browser...那么,小程序和 Adobe Flash 可能是增强浏览器功能的解决方案......

Did you try adding a closeHandler via Window.addCloseHandler() .您是否尝试通过Window.addCloseHandler()添加 closeHandler 。 It's called when the user closes the window/tab.当用户关闭窗口/选项卡时调用它。 In the handler you could send a close message or something to the server.在处理程序中,您可以向服务器发送关闭消息或其他内容。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM