Showing alert in angularjs when user leaves a page

后端 未结 6 649
借酒劲吻你
借酒劲吻你 2020-11-28 22:04

I\'m an angularjs new bee. I\'m trying to write a validation which alerts the user when he tries to close the browser window.

I have 2 links on my page v1 and v2.Whe

6条回答
  •  情书的邮戳
    2020-11-28 22:15

    The code for the confirmation dialogue can be written shorter this way:

    $scope.$on('$locationChangeStart', function( event ) {
        var answer = confirm("Are you sure you want to leave this page?")
        if (!answer) {
            event.preventDefault();
        }
    });
    

提交回复
热议问题