onbeforeunload 事件
代码如下:
window.onbeforeunload = function (e) { e = e || window.event; if (e) { e.returnValue = ‘确定离开吗?‘; } return ‘确定离开吗?‘; };
或者下面这种方式:
onbeforeunload 事件在即将离开当前页面(刷新或关闭)时触发。
原文:https://www.cnblogs.com/hool/p/12942662.html