JavaScript before leaving the page

前端 未结 10 1898
谎友^
谎友^ 2020-11-22 08:01

I want to make a confirmation before user leaving the page. If he says ok then it would redirect to new page or cancel to leave. I tried to make it with onunload

<         


        
10条回答
  •  不知归路
    2020-11-22 08:37

    In order to have a popop with Chrome 14+, you need to do the following :

    jQuery(window).bind('beforeunload', function(){
        return 'my text';
    });
    

    The user will be asked if he want to stay or leave.

提交回复
热议问题