You are here: irt.org | FAQ | JavaScript | Referrer | Q499 [ previous next ]
You need to use a frameset with a hidden frame:
<html> <frameset rows="100%,*"> <frame src="apage.html"> <frame src="blank.html"> </frame> </html>
Then when you want to display a link to take the user back to the referring document:
<script language="JavaScript"><!-- if (parent.document.referrer != '') document.write("Go back where you came from".link(parent.document.referrer)); //--></script>
This does not work in Internet Explorer, as the documents referrer property is broken.
Albert Grant writes:
I had one problem with this- when I returned to the referring URL it was still in the hiddem frame. This sent me on a long quest to solve that issue. The solution was: Include the following code in each page you want the folks to go back from:
<script language="JavaScript"><!-- if (top.document.referrer != '') document.writeln('<a href="' + top.document.referrer + '" target="_top">Go back to where you started</a>'); //--></script>
You could always put it in a "blank.html" file so it would always be at the bottom of the screen, but that would eat up some valuable viewing space. (my site as an example below). In this case you would have to define the "rows" in the "frameset" statement in index.html to be less than 100% (I used 93%).
For an example go to: http://www.southriver.com/refsites.html and click the link to "Web-Busters" - Then click on the "Go back..." link. It will bring you back to the URL where you entered the Web-Busters site from. Please bear in mind that this only works if they entered your site by clicking on a link.