如何检测用户是否在PHP中离开页面 [英] How to detect if a user leaves a page in PHP

查看:296
本文介绍了如何检测用户是否在PHP中离开页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在用户离开特定页面时执行此功能。此函数将基本上更改数据库中某列内的所有数据。因此,如果用户离开此页面,我希望系统执行此功能。有没有办法检测用户是否已离开页面。

There is this function which i want to execute in case the user leaves a particular page. This function will basically change all of the data within a certain column in my database. So in case the user leaves this page, i want this function to be performed by the system. Is there a way to detect if the user already left the page.

谢谢!

推荐答案

100%可靠,不,它是不可能。由于离开特定页面是客户端操作,因此您无法控制客户端执行的操作。您可以通过Javascript注册 onbeforeunload 处理程序,并希望客户端浏览器支持它。但同样,对此的支持并不普遍。

With 100% reliability, no, it's not possible. Since leaving a particular page is a client-side operation, you have 0 control over what the client does. You can register an onbeforeunload handler via Javascript and hope that the client browser supports it. But again, support for this isn't universal.

这篇关于如何检测用户是否在PHP中离开页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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