Display a warning with 'onbeforeunload' when leaving a page, except if 'Submit' is clicked

you could use jquery .on() to set onbeforeunload and then use .off() in form submission

// Warning
$(window).on('beforeunload', function(){
    return "Any changes will be lost";
});

// Form Submit
$(document).on("submit", "form", function(event){
    // disable unload warning
    $(window).off('beforeunload');
});

you can try this: set a flag when submit button is clicked and use this flag to check if the user has clicked submitted or leaving the page halfway

Pseudo code:

var submit_clicked = false;

$('input[type="submit"]').click(function(){
    submit_clicked = true;
});


window.onbeforeunload = function closeEditorWarning () {

  /** Check to see if the settings warning is displayed */
  if(($('#unsaved-settings').css('display') !== 'none') && 
      submit_clicked === false) {
    bol_option_changed = true;
  }

  /** Display a warning if the user is trying to leave the page with unsaved settings */
  if(bol_option_changed === true){
    return '';
  }


};