How can I confirm if the user actually left the page, because when I click on the browser to exit and say that I want to remain it turns the name of my a
into 1 and then does not return to 0. Does anyone have a solution? Code below:
<!DOCTYPE html>
<html>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
window.onbeforeunload = closeSession;
function closeSession() {
if (true) {
var a = document.getElementById('a');
if (a.name != 1) {
$.ajax({
url: "teste.php",
type: "GET",
async: false,
cache: false,
data: {
'nome' : "Rogers2",
'senha' : "123456"
}
});
return "disconnected";
}
} else {
a.name = 0;
}
}
</script>
<body>
<p>Close this window, press F5 or click on the link below to invoke the onbeforeunload event.</p>
<a href="teste2.php" onclick="this.name = 1" id="a" name="0">teste2</a>
</body>