Click here to Skip to main content
16,012,082 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have one confirm message which contain two button ok and cancel for closing the page ....

When I click OK the page need to close and clicking the cancel the page will stay...

But in my coding the cancel button clicks the page get close....

I know my coding is in error...But I cant get where the error is......

my code is here...
C#
if (!isClose) {
                    var agree;
                    agree = confirm('Are you sure to close the window');
                    if (agree) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }


Can anyone help me....
Posted
Comments
Sergey Alexandrovich Kryukov 9-Apr-12 17:59pm    
Where did you get this isClose? it means nothing, so the confirmation is never triggered...
--SA

You need to use beforeunload event. The answer to this question shows how to do it with jQuery:
http://www.mkyong.com/jquery/how-to-stop-a-page-from-exit-or-unload-with-jquery/[^].

Please see the source code and run demo page to see how it works.

—SA
 
Share this answer
 
hi,

replace your code with the following:

C#
if (!isClose) {
               if (confirm('Are you sure to close the window?')) {
                   //close code here                   
                   return true;
               } else {
                   return false;
               }
           }

hope this will help you. good luck.
 
Share this answer
 
v2
Comments
vivekx2 9-Apr-12 6:51am    
sorry its not working....

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