这是我的JS代码,它将在关闭浏览器或选项卡时执行。在关闭浏览器之前,这会使用户状态为离线
function checkBrowser(){
function warning(){
if($('#loginOrNot').val() == 'loggedIn'){
setTheExpertStatusToOffline();
cleanUpChat();
alert("You are leaving the page");
}
}
window.onbeforeunload=warning;
}
documnet.ready()上的正在调用checkBrowser()方法,因此它将绑定浏览器关闭的函数。现在的问题是working perfectly fine in all browsers but not in Chrome
。这里有什么不对吗?
答案 0 :(得分:0)
您必须在函数末尾返回一个字符串。然后,浏览器将显示一个确认框,包括您的消息。
function warning(){
if(true){
console.log('leaving');
return "You are leaving the page";
}
}
window.onbeforeunload = warning;