2
Colleagues.
How I would make the user when closing the browser or tab, was directed to another page, but that did not work when F5. I say this because I have a system that has online and offline status and many of them are closing through the browser or tab and the status is still online. The idea is when to close the browser or tab, to be directed to a page where I could disconnect it from the system and then close the browser.
Looking from here and there, I found this code, but it’s not working, but it can be a starting point... look:
<script>
var check;
function fechasess(url,e) {
if (url == 'f5') { //Entra quando uma tecla é apertada
if (e.keyCode == 116) { check = 1; } //Verifica se a tecla é F5 no IE, se for bloqueia o logout
if (e.which == 116) { check = 1; } //Verifica se a tecla é F5 no FF, se for bloqueia o logout
}else if (url == 'logout.php') { //Entra quando o onunload ativa
if (check != 1) { document.location=(url); } //Verifica se deve ativar o logout ou não
}else{ //Entra quando for um link
check = 1; //Bloqueia o logout
document.location=(url); //Redireciona o link
}
}
</script>
<body onkeydown="fechasess('f5',event)" onkeypress="fechasess('f5',event)" onbeforeunload="fechasess('logout.php')" onunload="fechasess('logout.php')">
It seems you want something impossible, but I don’t know if I got it right. You can only intercept the output of the page by events
unload
andbeforeunload
, and they rotate both when closing the tab or window, and when reloading the page. But I didn’t quite understand the idea of redirecting when the person tries to close the browser. If it will be closed, it wouldn’t do any good to redirect. And obviously a page can’t stop anyone from closing the browser.– bfavaretto
rs rs... I thought that with jquery or ajax nothing was impossible... but come on... with jquery I found this code: $(window). Unload(Function(){ Alert("Goodbye!"); }); I also found this code: <body onbeforeunload="Return myFunction()"> But I only need to disconnect the system user, put a url('quit.php') for example, just read this file and continue executing the closing of the page...
– user24136