Click here to Skip to main content
15,116,813 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
I have a requirement to show to user confirmation alert. AS my requirement to know when user clicks on the "leave the page" anf when "Stay on the page". Based on the user clicks on the button i need to do functionality.

Please help us


Thanks for your help.
Posted

$(window).on("beforeunload", function () {

return "are you sure you want to leave?";
});
   
Quote:
However there is no direct way. Hope this will work. Happy coding!!:)



<html>
<head>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script>
backagain=0;
close = 0;
$( window ).bind( 'beforeunload' , function( event ) {
setTimeout( function() {backagain++;);
return '';}).bind( 'unload', function( event ) {close++;});
</script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>

</body>
</html>



JS Bin
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900