I'm basically trying to make a computer based training module. We had to choose a topic and basically make a module that is to educate someone on the topic. At the end of the section there will be a quiz top test you on what you learn. We need to have an index or beginning page that lists all of the sections out so that the user can start wherever they want. I have all of my data done, but now I need to start the javascript. I wants it so that when you enter a section the page the user is on should be tracked. If for some reason the user closes the browser, he or she should be able to start on the page of the section they were on when the browser closed. For example if they were on the third page of the section when the browser was closed they would go back to the module later choose the section they were reading and it would remember and load the third page.
I created this set and retrieve function on each page of the module:
CODE
function setCookie(name,data,days)
{
var cookieEnabled=(navigator.cookieEnabled)? true : false
days=10;
if (days)
{
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
if(typeof navigator.cookieEnabled=="undefined" && !cookieEnabled)
{
alert('cookies not enabled');
}
else
{
var cookieName=name;
document.cookie=cookieName+'='+data+expires;
}
}
function retCookie(cookieName)
{
var myCookie;
var name=cookieName;
if(document.cookie)
{
index=document.cookie.indexOf(name);
if(index!=-1)
{
nameStart = (document.cookie.indexOf("=", index) + 1);
nameEnd = document.cookie.indexOf(";", index);
if(nameEnd==-1)
nameEnd=document.cookie.length;
myCookie=document.cookie.substring(nameStart,nameEnd);
}
}
return myCookie;
and this in the bodytag of each page
CODE
<body bgcolor="#CCCCCC" onLoad="setCookie('lastPage',document.location, 'cdRom',document.location)">
I've only used this one of of the module links so far:
CODE
<p><strong>Module 4</strong>: <a href="javascript: window.open( retCookie('lastPage'),'fullscreen')">Optical Drives</a><br>
I didn't think about what will happen if they close the browser come back start a whole different section. the cookie from before will interfere and it'll send them to the wrong place. Is there anyway I can adjust this so that if you want to start a new section the cookie from before won't interfere?