Ok, I have a problem with the following code. What happens when a user closes his browser, he must ask them to either click "OK" or "CANCEL" to exit the page. Clicking on OK will cause window.location to be redirected to another page to track users (and, yes, to avoid fiery wars, there is a secondary system to ensure accurate tracking in case the user killed the browser from the task manager (as mentioned in similar issues)). CANCEL will remain on the page because the problem is that no matter which button you click, you are redirected as if you want to leave the page. The corresponding code is below.
window.onbeforeunload = confirmExit;
function confirmExit()
{
var where_to = confirm("Click OK to exit, Click CANCEL to stay.");
if (where_to == true)
{
window.location="logout.php";
}
if (where_to == false){
alert("Returning...");
}
}