Disable “Changes you made may not be saved” pop-up window

后端 未结 3 1029
谎友^
谎友^ 2020-12-03 10:45

I use the following frontend code to export a .csv document.

HTML

  
3条回答
  •  一向
    一向 (楼主)
    2020-12-03 11:25

    @Dekel helped me to get it.

    The message is the beforeunload event. And I can disable it with window.onbeforeunload = null;.

    JS

      $('#export-link').click(function(e) {
        window.onbeforeunload = null;
        e.preventDefault();
        var link = $(this);
        var form = link.closest('form');
    
        var project_id = proj_id.find(":selected").val();
        var input = $('').attr('type', 'hidden').attr('name', 'project_id').val(project_id);
        form.append($(input));
    
        var project_type = proj_type.val();
        input = $('').attr('type', 'hidden').attr('name', 'project_type').val(project_type);
        form.append($(input));
    
        form.submit();
      });
    

提交回复
热议问题