角:关闭窗口上用户注销

编程入门 行业动态 更新时间:2024-10-08 04:29:36
本文介绍了角:关闭窗口上用户注销的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

角:关闭窗口上用户注销

本文发布于:2023-11-03 04:59:36,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1554299.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:关闭窗口   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!