Situation
I have a system in which I need the user to be logged off when I close the browser.
Code
In this way I managed to get the browser closing, or rather to 'exit' the page for a new one (or not in case of browser closing). But it's blocking my confirmation.
var myEvent = window.attachEvent || window.addEventListener;
var chkevent = window.attachEvent ? 'onbeforeunload' : 'beforeunload'; /// make IE7, IE8 compatable
myEvent(chkevent, function(e) { // For >=IE7, Chrome, Firefox
var confirm = window.confirm('Deseja fazer logout?');
if(confirm){
logout();
}
});
function logout (){
console.log('Logout');
}
Error
Blocked confirm ('Do you want to logout?') during beforeunload
Anyone else have a way to do this?