I know how to implement back button in AngularJS: How to implement history.back() in angular.js
And I want to display it only when BACK would lead me to the same application:
<a ng-click="back()" ng-show="isBackAvailable()">BACK</a>
I would like BACK to be hidden if it would lead to some other page.
My current implementation looks like this:
app.run(function($rootScope, $window) {
var acceptableReferrers = ["http://127.0.0.1:9000/"];
$rootScope.back = function() {
$window.history.back();
}
$rootScope.isBackAvailable = function() {
var result = _.contains(acceptableReferrers, document.referrer);
console.log(result)
return result;
}
});
This does not work.
When I paste http://127.0.0.1:9000/
into the browser bar the document.referrer
is ""
(empty string). However if I do this the following way:
<a href="http://127.0.0.1:9000/#/search">now referrer will be correct</a>
Please advise.