我有一个角应用中,当用户登录,我设置了分贝他的状态为在线。如果用户关闭浏览器,而不是执行菜单操作注销,我怎么可以更新他的脱机状态?我试图用$ 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.
更多推荐
角:关闭窗口上用户注销
发布评论