如果用户关闭浏览器,则需要触发,以便在15分钟的浏览器会话结束后将用户的状态从在线变为离线。
答案 0 :(得分:0)
绑定事件监听器以卸载并使用Navigator.sendBeacon发送请求,如下所示:
window.addEventListener("unload", yourFunction, false);
function yourFunction() {
navigator.sendBeacon(url, data);
}
答案 1 :(得分:0)
如果要在Angular中实现
@HostListener('window:beforeunload', ['$event'])
handleBeforeUnload(event) {
//添加确认框并相应地放置代码 }
并实现ComponentCanDeactivate。
希望这对您有所帮助。