角:关闭窗口上用户注销 [英] Angular: user logoff on closing window

查看:81
本文介绍了角:关闭窗口上用户注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个角应用中,当用户登录,我设置了分贝他的状态为在线。
如果用户关闭浏览器,而不是执行菜单操作注销,我怎么可以更新他的脱机状态?
我试图用$ window.onbeforeunload事件并调用Web服务来注销用户。
在code运行,但似乎执行将被切断,由浏览器:该服务从来没有所谓的真正的

I have an angular application where, when a user logs in, I set his status to "online" on the db. If this user close the browser, instead of performing the menu action logout, how can I update his status to "offline"? I tried to use the "$window.onbeforeunload" event and call a web service to logout the user. The code runs but it seems that the execution would be "cut off" by the browser: the service is never called "really".

推荐答案

使用一个WebSocket连接或轮询和侦听关闭服务器/停止。

Use a WebSocket connection or polling, and listen for that to close/stop on the server.

作为@安东尼奥说,你可以不依赖于客户端上的一贯通知您,它的关闭。

As @António says, you cannot rely on the client to consistently notify you that it's closing.

这篇关于角:关闭窗口上用户注销的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆