1

在我的主页上有这样的东西:

<script language="javascript">


   window.onbeforeunload = function(evt) {
        var message = 'Are you sure you want to leave?';
        if (typeof evt == 'undefined') {
            evt = window.event;
        }       
        if (evt) {
            evt.returnValue = message;
        }
        return message;
    } 


</script>

我想要做的是调用我的注销代码以释放所有资源,但只有当用户按下离开页面底部时,这可能......知道用户选择了女巫选项吗?

谢谢大家,最好的问候

4

2 回答 2

0

使用onunload事件:

window.onunload = function () {
    // your logout code
};
于 2012-12-13T21:01:17.600 回答
0
var myclose = false;
$(window).on('beforeunload', function(){
     var messege = 'You have closed the browser. Do you want to logout from your application?';
    setTimeout('myclose=false',10);
    myclose=true;
    return myclose;
});
$(window).on('onunload', function(){
    if (myclose==true) 
    {
        //the url of your logout page which invalidate session on logout 
        alert('hello');
        location.replace('logout.php') ;
    }
});

    var myclose = false;
    $(window).on('beforeunload', function(){
         var messege = 'You have closed the browser. Do you want to logout from your application?';
        setTimeout('myclose=false',10);
        myclose=true;
        return myclose;
    });
    $(window).on('onunload', function(){
        if (myclose==true) 
        {
            //the url of your logout page which invalidate session on logout 
            alert('hello');
            location.replace('logout.php') ;
        }
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
于 2021-01-29T11:50:26.583 回答