How to prevent the user to change page with jQuery

后端 未结 2 1971
天命终不由人
天命终不由人 2021-01-12 05:49

I have a page with a form that is submittes via ajaxSubmit() (so, without changing the page).

My goal is that, when the user try to change page (or even to close the

相关标签:
2条回答
  • 2021-01-12 06:38

    It's possible bind the "onbeforeunload" event with jQuery:

    $(window).bind('beforeunload', function(e) {
        return "ATTENZIONE!!";
    });
    

    It works!!

    0 讨论(0)
  • 2021-01-12 06:42

    try the following. Demo here

    <script type="text/javascript">
    
           function unloadPage(){
               return "dont leave me this way";
           }
    
           window.onbeforeunload = unloadPage;
    
    </script>
    
    0 讨论(0)
提交回复
热议问题