1

In popup page after enter the data before clicking the save button user try to close the popup in (X mark) i want to show the alert message(You did not save your changes). if user click the save button no need to show the alert message.

using javascript how can i do this ?

<script type="text/javascript">
 $(document).ready(function () {

     var unsaved = false;
     $('#Button1').click(function () {
         unsaved = true;
     });

     function unloadPage() {
         if (unsaved) {
             return "You have unsaved changes on this page.?";
         }
     }

     window.onbeforeunload = unloadPage;
 });

</script>
elina
  • 189
  • 2
  • 9
  • Try [this](https://jsfiddle.net/Jaydeep_Mor/h075qdqr/1/) it may help you. – Jaydeep Mor Jul 03 '17 at 04:51
  • I don't think any browsers actually display the message you want any more, they all display a "default" message – Jaromanda X Jul 03 '17 at 04:51
  • 1
    Possible duplicate of [Warn user before leaving web page with unsaved changes](https://stackoverflow.com/questions/7317273/warn-user-before-leaving-web-page-with-unsaved-changes) – barzin.A Jul 03 '17 at 04:53

1 Answers1

0

used below technique may be it is useful

      var is_template_save;
if (is_need_save == '0') {
    is_template_save = false;
} else {
    is_template_save = true;
}

window.onbeforeunload = function () {
    if (is_template_save) {
        return "Did you save your template?"
    }
}
function template_save() {
    is_template_save = false;
}
function template_unsave() {
    is_template_save = true;
}

Hope it make sense

Sachin Sarola
  • 993
  • 1
  • 9
  • 26