Check if changes saved before unload

后端 未结 2 1337
离开以前
离开以前 2021-01-22 10:41

I have the following JavaScript

EDIT: included assignments for changesSaved

 var changesSaved = true;

    $(document).ready(function ()         


        
2条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-22 11:10

    window.onbeforeunload = function () {
         var changesSaved = confirm("You havent saved your changes. Are you sure you want to leave the page?");
        if (changesSaved) {
            return true;
        } else {
            return false;
        }
    

提交回复
热议问题