Although I'm not entirely sure, after debugging for a while and looking at some examples through Google, I came to the conclusion that document.referrer
is always empty on localhost
.
Is there any other way to get the URL of the previous page? Or a way to test document.referrer
on localhost
?
I have an <a>-tag
on my page:
<a data-ng-click="backClick()">Return to previous page</a>
With the following function
in my AngularJS controller:
$scope.backClick = function () {
if (document.referrer.indexOf(window.location.host) >= 0) {
history.go(-1);
}
else {
window.location.href = '#/';
}
return false;
};
But when I debug this in Chrome, document.referrer
is always ""
, so it always goes to the else
.