Here is a solution with Angular.
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?'); } }); });
I use a launcher to run this. First I save the actual location in $ rootScope.actualLocation, then I listen to $ locationChangeSuccess, and when that happens, I update the actualLocation with the new value.
In $ rootScope, I observe changes in the location path, and if the new location is equal to the previous one, this is because $ locationChangeSuccess was not started, that is, the user used the history back.
Bema Apr 04 '13 at 16:22 2013-04-04 16:22
source share