You can do this with the following script.
<script type="text/javascript">
window.onbeforeunload = function(){ return;}
</script>
However, if you plan to cancel the navigation, just do not worry. As far as I know, this is not possible.
The code below checks if the user clicked the link.
var checkAnchorClick = false;
$(document).ready(function () {
$("a").live("click", function () {
checkAnchorClick = true;
});
});
$(window).unload(function () {
if (checkAnchorClick)
alert("User clicked a link...");
else
alert("Something else...");
});
source
share