扫码关注官方订阅号
怎么监听手机浏览器离开网页,PC端 用了onbeforeunload可以监听到。
光阴似箭催人老,日月如移越少年。
var MSG_UNLOAD="如果你此时刷新页面,页面信息可能会丢失,确认刷新吗?"; var UnloadConfirm = {}; //启用监听浏览器刷新、关闭的方法 UnloadConfirm.set = function(confirm_msg){ window.onbeforeunload = function(event){ event = event || window.event; event.returnValue = confirm_msg; } } //关闭监听浏览器刷新、关闭的方法 UnloadConfirm.clear = function(){ window.onbeforeunload = function(){}; } UnloadConfirm.set(MSG_UNLOAD);
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
光阴似箭催人老,日月如移越少年。