Go Back   CodingForums.com > :: Client side development > JavaScript programming > Post a JavaScript

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-03-2002, 03:35 AM   PM User | #1
x_goose_x
Regular Coder

 
Join Date: Jun 2002
Location: Montreal, Canada
Posts: 644
Thanks: 0
Thanked 0 Times in 0 Posts
x_goose_x is an unknown quantity at this point
History menu for your site.

This script keeps a history of the pages previously visited on your site with links pointing to the page.

Just add the following to your head:

Code:
<script>
pagetitle = "Local News Page"; // This is what appears in the history list
</script>
<script src="history.js"></script>
and add the following to where you want the history list to appear:

Code:
<div id="Histbox"></div>
and put the following in a .js file named history.js:

Code:
frstvst = "Welcome!"; // If there is no history, this should be displayed.
histlen = 5; // Number of sites back to keep in history
splitter = " - "; // Enter what you'd like to be put in between the items in the history list (HTML) use <br> to put each on a seperate line.

kookz = document.cookie;
kookz2 = kookz.split(",");
kookz3 = new Array();

function loader() {
	pgtitle = pagetitle+"-"+location.href;
	if (kookz) {
		y = 0;
		z = kookz2.length;
		for (x=0; x<z; x++) {
			if (kookz2[x]==pgtitle) {
				y++;
				z--;
			}
			if (kookz2[x+y]) {
				kookz3[x] = kookz2[x+y];
			}
		}
		if ((histlen-kookz3.length)<0) {
			t = kookz3.shift();
		}
		divhtml = "";
		for (x=0; x<kookz3.length; x++) {
			dash = kookz3[x].indexOf("-");
			histhref = kookz3[x].substring(dash+1,kookz3[x].length);
			histlink = kookz3[x].substring(0,dash);
			divhtml += "<a href='"+histhref+"'>"+histlink+"</a>";
			if ((x+1)<kookz3.length) {
				divhtml += splitter;
			}
		}
		document.getElementById("Histbox").innerHTML = divhtml;
		kookz3[kookz3.length] = pgtitle;
		document.cookie = kookz3;
	}else {
		document.cookie = pgtitle;
		document.getElementById("Histbox").innerHTML = frstvst;
	}
}

window.onload = loader;
I've tested it in IE6 and Moz1.1

I will also attach a zip file containing the appropriate files.

See it in action:

History test
Attached Files
File Type: zip history.zip (904 Bytes, 266 views)

Last edited by x_goose_x; 09-03-2002 at 03:47 AM..
x_goose_x is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:56 AM.


Advertisement
Log in to turn off these ads.