0

Here is my JS code which will be executed when close the browser or the tab. Which will makes the user status as offline before closing the browser

function checkBrowser(){
   function warning(){
        if($('#loginOrNot').val() == 'loggedIn'){
          setTheExpertStatusToOffline();
          cleanUpChat();
          alert("You are leaving the page");
        }
   }
   window.onbeforeunload=warning;
} 

on documnet.ready() am calling checkBrowser() method, so that it will bind the function for browser close. Now the problem is this is working perfectly fine in all browsers but not in Chrome. Whats wrong in here?

4

1 回答 1

0

您必须在函数末尾返回一个字符串。然后,浏览器将显示一个确认框,包括您的消息。

http://jsfiddle.net/fxtBC/

function warning(){
    if(true){
      console.log('leaving');
      return "You are leaving the page";
    }
}
window.onbeforeunload = warning;​ 
于 2012-08-02T14:03:00.710 回答