$(window).unload is not firing

后端 未结 6 1804
失恋的感觉
失恋的感觉 2020-11-28 15:23

I want to execute an action method when the user is abandoning a particular page using jQuery.

The page has the following code:

    

        
6条回答
  •  半阙折子戏
    2020-11-28 15:48

    window.onbeforeunload=navigationError;
    
    var dont_confirm_leave = 0; var leave_message = 'You sure you want to leave?';
    
    function navigationError(e) 
      {
        if(dont_confirm_leave!==1)
        {
          if(!e) e = window.event;
          //e.cancelBubble is supported by IE - this will kill the bubbling process.
          e.cancelBubble = true;
          e.returnValue = leave_message;
          //e.stopPropagation works in Firefox.
          if (e.stopPropagation) 
          {
            e.stopPropagation();
            e.preventDefault();
          }
    
          //return works for Chrome and Safari
          return leave_message;
        }
      }
    

提交回复
热议问题