I'm done racking my brain by myself...need A LOT of help!

admin

Administrator
Staff member
Hello everyone,

I hope this solution comes a lot easier for you.

It's a little difficult to explain, but I will do my best. Please feel free to ask about anything that is not clear.

On 10 pages of a web-like presentation, I have a function that checks the amount of time a viewer has spent on a page against a predefined time value (i.e. 3 minutes) when the viewer is trying to advance to the next page.

If the viewer has not spent at least the amount of time specified by the predefined time value when trying to advance to the next page, the viewer is notified with the following statement:

"You're reading awfully fast. Don't you think you should take it a bit more slowly?"

However, within those 10 pages are links to photos, .pdf documents, and references. The links to these items are not restricted by the page's timer.

I need to keep track of the time a viewer has spent on a page, even after accessing material from an unrestricted link within the timed page.

Here is an example:

You access page 2 of the presentation which has a minimum time restriction of 3 minutes (which you don't know of course). A quarter-way down the page, you follow a link to view some photos and before accessing the photos you had spent 45 seconds on the page. You now have 2 minutes and 15 seconds remaining on the timed page.

When you return to the timed page from the photos, you continue reading. Three quarters down the page, you follow a link to the "Notes" page where references are listed. Before accessing the "Notes" page you had spent 2 minutes and 15 seconds total on the page. You now have 45 seconds remaining on the timed page.

How would I use cookies to retain the value of "TimeSpent" and use that value when the viewer returns to the timed page from a link which is not restricted by the timer?

I have the following cookie, but I don't think it works the way I would like it to and this is because when the viewer returns to the time-restricted page, the function "checkspeed" will only test the value of the last recorded value for "TimeSpent" as opposed to the value of the TOTAL time the viewer has spent on the page.

Take a look:

<html>
<head>
<title>Timed Page Cookie TEST</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript" type="text/javascript">
<!--

TimeIn = new Date();

function SetCookie() {
var TimeOut = new Date();
var today = new Date();
var expire = new Date();
var nDays=2
var cookieName="PageTimer";
var TimeSpent=(TimeOut - TimeIn)
var cookieValue=TimeSpent;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
return (TimeSpent);
}

function ReadCookie() {
var NameOfCookie="PageTimer";
if(document.cookie.length > 0)
{
begin = document.cookie.indexOf(NameOfCookie+"=");
if(begin != -1)
{
begin += NameOfCookie.length + 1;
end = document.cookie.indexOf(";",begin);
if(end == -1) end = document.cookie.length;
TimeSpent=(document.cookie.substring(begin,end));
}
}
}

function checkspeed() {
ReadCookie(PageTimer);
TimeToExit= new Date();
difference = TimeToExit - TimeSpent;
if (difference <= 60000 ){
alert("You're reading awfully fast. Don't you think you should take it a bit more slowly?");
return false;
}
else {
return true;
}
}

//-->
</script>
</head>

<body onLoad="SetCookie();">
This link will allow users to view <a href=http://www.webdeveloper.com/forum/archive/index.php/"photos.htm" onClick="SetCookie();">refernced material</a>. <br>
This link goes to the next page and is timed. <a href="page3.htm" onClick="return checkspeed();">Next
Page</a>
</body>
</html>

What do I need to do??

Thank you.

~Darron
 
Back
Top