如何触发onb​​eforeunload($ destroy)

时间:2015-08-27 13:48:31

标签: angularjs

如果某些数据发生变化,我将不得不停止卸载。我试过这个,但没效果

$scope.changed = true;

$scope.$on('$destroy', function () {
   if ($scope.changed) {
     alert('Let me clean up first !');
     return ;
   }
});    

fiddle

1 个答案:

答案 0 :(得分:0)

这个小代码可以帮助我。

    $scope.changed = true;

    window.onbeforeunload = function(event){
     if ($scope.changed) {
       event.preventDefault();
       return ;
     }
   }; 
相关问题