Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

trace movement through a site

Status
Not open for further replies.

gecko101

Programmer
Feb 7, 2005
9
AU
Hi,
I would like to place on the end of the URL a list of the previous pages a person has been to so a back button can be created to go to the previous page. The javascript:history.back() does not always work correctly because the pages have named anchors( <a name="a"> <a href="#a">)on them.

I can do this for 1 back by placing the current page name on any links away from the page eg. <a href="page2.html?from=page1.html">next</a>.

Then on page2. the next link I would like to be somthing like this <a href="page3.html?from=page2.html&back1=page1.html">

Is there code out to do this?, if not would it be easy to work out. (Im not to good at javascript yet)

The following code I use for the first pages, but not the following ones,
Code:
<script language="javascript">
   
   //<!-- do not change any of this script
   
   var searchString = document.location.search.substring(1);
   
   var nameValuePairs = searchString.split("&");
   var params = new Array();
   
   for ( var i=0; i< nameValuePairs.length; i++){
   
        var dataValues = nameValuePairs[i].split("=");
        var name  = dataValues[0]; 
        var value = dataValues[1];      
        params[ name ] = unescape( value );
   }
   
   // -->
   
   </script>
</body><body>
   <script>
	if(params["from"]) 
	    document.writeln("<a href='" + params["from"] + "' class='button'>Back</a><br />");
	else
	    document.writeln("<a href='javascript:history.back()' class='button'>Back</a><br />");
   </script>
 
another posiability might be to have a counter increment each time a named anchor is clicked, then the back button could some how call a history.back(-counter).
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top