onbeforeunload 事件在即将离开当前页面(刷新或关闭)时触发。
代码如下:
window.onbeforeunload = function (e) { e = e || window.event; if (e) { e.returnValue = '确定离开吗?'; } return '确定离开吗?'; };
或者下面这种方式:

网站:http://shibowl.top
github:https://github.com/hanbinjxnc
博客园:https://www.cnblogs.com/hool
博客:https://blog.shibowl.top
淘宝店:https://boxunwl.taobao.com/
作者:世博 2019年4月28日----
github:https://github.com/hanbinjxnc
博客园:https://www.cnblogs.com/hool
博客:https://blog.shibowl.top
淘宝店:https://boxunwl.taobao.com/
作者:世博 2019年4月28日----
浙公网安备 33010602011771号