How to prevent the user to change page with jQuery

后端 未结 2 2010
天命终不由人
天命终不由人 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!!

提交回复
热议问题