Reputation: 41
I'd like to display a back button with the help of history.back, but it should only be displayed if the history page is within the same website / domain. So it should not be displayed if referrer is e.g. google.com. Couldn't find a working solution yet.
Is this possible?
Thx
Upvotes: 4
Views: 911
Reputation: 37543
Referer in javascript is tricky because different browsers support it differently. My preferred method is to catch the referrer using code behind of whatever language I'm using to produce the page and then pass it into the page as a javascript variable. A C# example:
<script language="javascript" type="text/javascript">
var referer = '<%= Request.UrlReferrer %>';
</script>
Upvotes: 1