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.

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

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

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


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