在javascript中关闭浏览器时将在线状态更改为离线状态? [英] Changing online status to offline when closing browser in javascript?

查看:159
本文介绍了在javascript中关闭浏览器时将在线状态更改为离线状态?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在javascript中关闭浏览器时将在线状态更改为离线状态?



- 这是否可行,因为我在window.onunload上看了一点 - 新手所以不是很了解。



如果我要记录timedstamp,离线时我需要一个DB条目吗?

Changing online status to offline when closing browser in javascript?

- Is this possible as I read a little on window.onunload - newbie so not very clued up.

If I want to log the timedstamp, when offline do I need a DB entry?

推荐答案

参考 - 让用户离线浏览器卸载事件 [ ^ ]。

Refer - MAKE A USER OFFLINE ON BROWSER UNLOAD EVENT[^].
引用:

d。)所以在所有这些事件上我发送一个更改数据库中的在线标志的ajax请求



f。)当用户回来时我检查该用户是否存在cookie,如果cookie存在然后我再次设置用户的在线标志。



这种方法有帮助,因为如果用户正在刷新页面,则用户仅在几毫秒内保持脱机状态。

d.) So on all these events i send an ajax request that changes the online flag in the db

f.) And when the user comes back i check whether the cookie exists for this user, if the cookie exists then i set the online flag of the user again.

This approach helps because if the user is refreshing the page then the user remains offline only for very few milliseconds.


这篇关于在javascript中关闭浏览器时将在线状态更改为离线状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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