Confirm box before closing a tab

后端 未结 1 1118
梦毁少年i
梦毁少年i 2021-01-03 10:07

I want to have a confirm box when user tries to close the window.

window.onbeforeunload = function (evt) {
    var mes         


        
相关标签:
1条回答
  • 2021-01-03 10:27

    I assume that on page load, you are setting up var sncro=1; and when some data changes, you adjust this value. Here is the quick check:

    window.onbeforeunload = function (evt) {
      if (sncro != 1) {
       var message = 'Are you sure you want to leave, cause there are some unsaved changes?';
       if (typeof evt == 'undefined') {
          evt = window.event;
       }
       if (evt ) {
          evt.returnValue = message;
       }
       return message;
      }
    }
    
    0 讨论(0)
提交回复
热议问题