I want to detect when user is leaving browser however I need to check on some condition, the script below skips the if(false) and always prompts for request regardless of returning true or false.
How can I let it check condition before prompting?
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-2.1.3.min.js"></script>
</head>
<body>
<script type="text/javascript">
$(document).ready(function ()
{
$(window).bind('beforeunload', function () {
if (false)
return "Are you sure? Your changes will be lost!";
else
return false; // or true doesn't matter
});
});
</script>
</body>
</html>