jQuery unload event only for close window not for Link navigation

前端 未结 4 1787
清歌不尽
清歌不尽 2021-01-07 13:14

I am using this code for logging out user when closes the page, but the user will logout also when clicking on other links (same website):

  $( window ).unlo         


        
4条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-07 13:45

    Try the following solutions, hope this helps

    
    

    or

    var logOutFlag = true;
    $('a').click(function(){
        logOutFlag = false;
    });
    $(window).bind('beforeunload', function(event) {
        if(logOutFlag){
             $.ajax({url:"?logout&leave=yes", async:false});   
        }
    });
    

提交回复
热议问题