【问题标题】:I want to get previous path on a button click event in angular.js我想在 angular.js 中的按钮单击事件上获取先前的路径
【发布时间】:2016-08-28 20:40:34
【问题描述】:

使用 angular.js 获取后退按钮单击事件的先前位置路径


我想要什么?

当我单击当前页面中的后退按钮时,我想转到上一页。

HTML

<input type="button" ng-click="back()" />

控制器

$scope.back=function()
{
// here i want to get the previous path(or url) 
}


我做了什么

我可以通过使用$locationChangeStart$locationChangeSuccess 来获取prev url

 $scope.$on('$locationChangeStart', function (evt, absNewUrl, absOldUrl) {
        var old = absOldUrl
    });

我不想要这种方式,我想在按钮点击事件上获得之前的URL

【问题讨论】:

    标签: javascript jquery html angularjs back


    【解决方案1】:

    试试这个:

    function back() {
        parent.history.back();
    }
    

    【讨论】:

    • 你能解释一下父母吗?
    • 当前frame的parent,也可以用window代替parent。
    【解决方案2】:
    app.run(function($rootScope) {
    $rootScope.$on('$locationChangeStart', function (evt, absNewUrl, absOldUrl) {
        absOldUrl=absOldUrl.substring(9);
        var aaa = absOldUrl.indexOf("/");
        $rootScope.PrevURL = absOldUrl.substring(aaa + 1);
    
        absNewUrl = absNewUrl.substring(9);
        var aaa = absNewUrl.indexOf("/");
        $rootScope.NextURL = absOldUrl.substring(aaa + 1);
    
        console.log($rootScope.PrevURL);
        console.log($rootScope.NextURL);
        })
    })
    

    【讨论】:

      猜你喜欢
      • 2018-11-10
      • 2017-11-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-08
      相关资源
      最近更新 更多