Link to home
Start Free TrialLog in
Avatar of NickMalloy
NickMalloyFlag for United States of America

asked on

Alert when navigating away from page

I'm working with an asp.net page within a masterpage. I am trying to alert people on an entry page when they try and leave the page. The message pops up just fine, but when I click cancel it still navigates away. What am I doing wrong?
jQuery(function ($) {

        /* global on unload notification */
        warning = true;

        if (warning) {
            $(window).bind("unload", function () {
                if (confirm("Do you want to leave this page") == true) {
                    //they pressed OK 
                    alert('ok');
                } else {
                    // they pressed Cancel 
                   // alert('cancel');
                    return false;
                }
            });
        }
    });

Open in new window

Avatar of Preece
Preece
Flag of United States of America image

I think

return false;

after

alert('ok');

will do the trick
 
Nevermind my last comment, did not read the code entirely...still looking...
ASKER CERTIFIED SOLUTION
Avatar of Preece
Preece
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial