2

On Internet Explorer, i am using below code

if (navigator.appName == 'Microsoft Internet Explorer' || !!(navigator.userAgent.match(/Trident/) || navigator.userAgent.match(/rv:11/)) || (typeof $.browser !== "undefined" && $.browser.msie == 1)) {
    window.onbeforeunload = function () {

            //return "Ticket upload progress will be lost if you close/reload this window.\nDo you really want to continue?"
            var message = confirm("Ticket upload progress will be lost if you close/reload this window.\nDo you really want to continue?");
            if (message == true) {
                alert(1);
            }
            else if(message == false) {
                return;
            }
    }
}

When user click on ok or cancel in both the conditions, page is closed.

I want to stay on same page, if user clicked on cancel. I have tried everything but not working.

Any help is highly appreciated.

  • Most (good) browsers won't let you do this for security reasons, to prevent sites making you stay on them when you try to close... (Spam pop-ups to make it impossible to close the site) – Milney Apr 20 '17 at 10:18
  • see here: http://stackoverflow.com/questions/276660/how-can-i-override-the-onbeforeunload-dialog-and-replace-it-with-my-own – Milney Apr 20 '17 at 10:19

1 Answers1

0

Try to replace

else if(message == false) {
    return;
}

with

else if(message === false) {
    return null;
}
Torben
  • 438
  • 1
  • 7
  • 22
  • After above change, I am getting Leave this page or Stay on this page message, actually i don't want any popup after that, i just want to stay on same page. – Open Source Training Apr 20 '17 at 10:15