Forum Moderators: open
Thanks,
Matthew
On arriving on the next page, the cookie is read, the string split into an array, you loop through the array and put the stored links in a variable that you can later display with document.write(). Than the URL and the title of the new page are stored, and if necessary the array will be trimmed to 10 or 20 items by popping the oldest item of the wagon. Next, store the array as a string in the cookie.
Is that what you were thinking of?
Now to try to figure out how to do it - I'm learning enough JavaScript that I think I'll get it eventually, but if someone could point out a few of the functions, objects or methods I'll need (are those even the right terms? Not sure...) I'd really appreciate it! ;)
Thanks again,
Matthew
I'll try to write a bit of code that may get you going. The worst and ugliest part is reading of the cookie.
// current page info
var curPage = '<a href="' + location.href + '">' + document.title + '<\/a>';
// set max # of pages in history list
var maxPages = 10;
// let's call our page info myhistory, and the page element histlist
var myhistory, histlist;
// check if cookie with past pages already exists
if (document.cookie.indexOf('myhistory=') > -1) { // myhistory exists
// a cookie string basically looks like myhistory=bladibla;othercookie=foobar;
// so the start of myhistory's value is at
var startpos = document.cookie.indexOf('myhistory=') + 10;
// now the endpos:
var endpos = document.cookie.indexOf(';', startpos);
// endpos == -1 if our cookie is the last one
if (endpos == -1)
endpos = document.cookie.length;
// now we can finally extract the value
myhistory = document.cookie.substring(startpos, endpos);
// unescape it and split it into an array
// we'll use ### as delimiter
myhistory = unescape(myhistory);
myhistory = myhistory.split('###');
// loop through this array and put links in histlist
// pro memoriam...
} else {
// make myhistory an empty array;
myhistory = new Array();
}
// now insert the current page at the start of the array
// [deity] knows why they call this method unshift...
myhistory.unshift(curPage);
// drop the last item if list is too long
if (myhistory.length > maxPages)
myhistory.pop();
// now store the joined items of the array in the cookie.
document.cookie = escape(myhistory.join('###'));
Completely untested...