Activating OnBeforeUnload ONLY when field values have changed

后端 未结 7 2119
暗喜
暗喜 2020-12-31 01:27

What I\'m trying to achieve is to Warn the user of unsaved changes if he/she tries to close a page or navigate away from it without saving first.

I\'ve managed to g

7条回答
  •  清歌不尽
    2020-12-31 02:21

    Try your logic in a different manner. Meaning, put the logic for checking the value of the input field in your onbeforeunload method.

    window.onbeforeunload = function () { 
        if ($("#is_modified").val() == 'true') { 
            return "You have unsaved changes."; 
        } else { 
            return true; // I think true is the proper value here 
        } 
    };
    

提交回复
热议问题