【问题标题】:how to trigger onbeforeunload ($destroy)如何触发 onbeforeunload ($destroy)
【发布时间】:2015-08-27 13:48:31
【问题描述】:

如果某些数据发生更改并且我必须先做一些事情,如何停止卸载。我正在尝试这个,但没有效果

$scope.changed = true;

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

fiddle

【问题讨论】:

标签: angularjs


【解决方案1】:

这个小代码可以帮助我。

    $scope.changed = true;

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-12-23
    • 2021-07-19
    • 2021-11-30
    • 2023-03-03
    • 2011-05-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多