jeudi 21 avril 2016

Laravel5.1 Logout when browser is close using javascript

How to detect that browser is close using javascript. I have not found any solutions using laravel. So now I am using jquery ajax request to logout before window is close. For this I am using-

function windowUnloaded() {

    var unloaded = false;
    $(window).on('beforeunload', unload);
    function unload(){      
        if(!unloaded){
            $('body').css('cursor','wait');
            $.ajax({
                type: 'get',
                async: false,
                url: '/logout',
                success:function(){ 
                    unloaded = true; 
                    $('body').css('cursor','default');
                },
                timeout: 5000
            });
        }
    }
}

This works only when I refresh page. But I want it when browser is close. Somebody can tell me from where I am wrong or If there is any other better solution. Thanks in advance.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire