onbeforeunload 事件
代码如下:
window.onbeforeunload = function (e) { e = e || window.event; if (e) { e.returnValue = '确定离开吗?'; } return '确定离开吗?'; };
或者下面这种方式: