【AngularJS】ブラウザバックを検出する方法。

いつもお世話になっておりますstack様に素晴らしいコードがあったのでペタリ。

myApp.run(function($rootScope, $route, $location){
   //Bind the `$locationChangeSuccess` event on the rootScope, so that we dont need to 
   //bind in induvidual controllers.

   $rootScope.$on('$locationChangeSuccess', function() {
        $rootScope.actualLocation = $location.path();
    });        

   $rootScope.$watch(function () {return $location.path()}, function (newLocation, oldLocation) {
        if($rootScope.actualLocation === newLocation) {
            alert('Why did you use history back?');
        }
    });
});

詳細は下記参照。

http://stackoverflow.com/questions/15813850/detect-history-back-using-angular