【问题标题】:Handle browser back button with angular in controller在控制器中处理带有角度的浏览器后退按钮
【发布时间】:2017-10-03 23:27:49
【问题描述】:

我想处理带有角度的浏览器后退按钮,我尝试了很多解决方案,但我找不到满足我要求的解决方案, 这是我尝试过的code

$scope.$on('$locationChangeStart', function(event, newUrl, oldUrl) {
   if(!allowed /* inject your logic here */) {
       event.preventDefault();
    }

});

当我从我的应用程序转到特定页面时它工作正常,但如果从例如 www.google.com 通过粘贴链接直接到该特定页面,那么它只会返回到 Google。

实际上我想要处理后退按钮的两种情况。
有可能吗?

我将非常感谢您的回复,
这些是我尝试过的链接,但问题仍然存在。
How to detect browser back button click event using angular?
How to handle browser back button event in a particular controller?

【问题讨论】:

    标签: javascript jquery angularjs routes back-button


    【解决方案1】:

    您是否尝试过使用“window.onbeforeunload”?

    例如:

    window.onbeforeunload = function() 
    { 
       //Do whatever here for example prompt user 
       return "Are you sure you want to go back?"; 
    };
    

    【讨论】:

      猜你喜欢
      • 2013-01-10
      • 2023-02-23
      • 2018-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-28
      • 2016-01-14
      相关资源
      最近更新 更多