I have a problem, I need to capture the closing of my browser with JavaScript in order to close the user's current session and thus validate that only one user session is open.
What I have tried so far is to capture the closing of the browser with onload and onbeforeunload as follows:
<body onload=sesionVerified() onbeforeunload=exitSesion() class="fixed-navbar">
And the JavaScript is as follows:
function sesionVerified() {
console.log("sesion activa");
}
function exitSesion() {
setTimeout(() => {
var idusuario = $("#txt_idusuario_general").val();
}, 100);
$.ajax({
url: "../controlador/usuario/controlador_cerrar_sesion.php",
type: 'POST',
data: {
id: idusuario
}
}).done(function (resp) {
var data = JSON.parse(resp);
})
}