How to disable beforeunload action when user is submitting a form?

前端 未结 7 2350
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 12:48

I have this little piece of code:



        
7条回答
  •  情深已故
    2020-11-28 12:56

    This is what we use:

    On the document ready we call the beforeunload function.

    $(document).ready(function(){
        $(window).bind("beforeunload", function(){ return(false); });
    });
    

    Before any submit or location.reload we unbind the variable.

    $(window).unbind('beforeunload');
    formXXX.submit();
    
    $(window).unbind("beforeunload"); 
    location.reload(true);
    

提交回复
热议问题