1

The intent of the code below is that the promptForSavingFormData will appear once the 2 conditions in the if-statement are met. Fortunately, this is occurring and the navigation window is appearing at the correct time. The navigation window is opening telling the user that they can continue with or without saving with 2 button options for these. The issue, however, is that before the user even has the chance to click one of those buttons in the navigation window, the page is incorrectly navigating to the page the user attempts to go to. This shouldn't be happening, however, until the user clicks to continue without saving or continue and save in the dialog window. Why is window.onbeforeunload still allowing this navigation until the user interacts with the navigation window? Any help would be appreciated. Thanks!

window.onload = function () {
   // initialize
   Sys.WebForms.PageRequestManager.getInstance().add_pageLoaded(pageLoadedTwo);

   // Notify Microsoft Ajax
   if (typeof (Sys) !== "undefined") Sys.Application.notifyScriptLoaded();
};

function pageLoadedTwo() {
   window.onbeforeunload = checkIfFormInStudentWindow;
}

function checkIfFormInWindow(e) {
   if (($("#searchWindow").is(':visible')) && (document.URL.indexOf('/NewForms/') > -1)) {
       return promptForSavingFormData();
   }
}

function promptForSavingFormData() {
   navigationWindow.center();
   navigationWindow.open();
}
CDA the Programmer
  • 87
  • 1
  • 6
  • 20

1 Answers1

2

I think this post will give you the answers you are after.

TLDR

// Enable navigation prompt
window.onbeforeunload = function() {
    return true;
};
// Remove navigation prompt
window.onbeforeunload = null;
T. Short
  • 3,481
  • 14
  • 30