关闭网页和浏览器前执行
window.onbeforeunload = e => {
e = e || window.event;
if (e) {
e.returnValue = 'close';
//这是自己的业务逻辑
$.ajax({
type: "POST",
url: "https://mock.uutool.cn/qqwwee",
data: {
username: '关闭'
},
success: function (data) {
console.log("发出去了");
}
})
//end
return 'close';
}
}