PDA

View Full Version : Indicate new content since last visit (for 3 days)



Beverleyh
03-16-2010, 12:58 PM
Hi,

Would it be possible for somebody to show me how to alter this script so instead of showing "new" content on the first page load since last visit, the "new" image indicator hangs around for 3 (or however many) days, regardless of how many subsesquent page loads there are.
At the moment it only shows on the first re-visiting page load so if a visitor misses it, thats it.

Here's the link: http://javascript.internet.com/cookies/new-to-you.html

And here's a copy of the code:
now = new Date
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+6)
lastVisit = new Date(cookieVal("pageVisit"))
document.cookie = "pageVisit="+now+";expires=" + expireDate.toGMTString()

function cookieVal(cookieName) {
thisCookie = document.cookie.split("; ")
for (i=0; i<thisCookie.length; i++) {
if (cookieName == thisCookie[i].split("=")[0]) {
return thisCookie[i].split("=")[1]
}
}
return "1 January 1970"
}

function newCheck(yyy,mm,dd) {
lastChgd = new Date(yyy,mm-1,dd)
if (lastChgd.getTime() > lastVisit.getTime()) {
document.write("<img src='/img/new-to-you/new.gif' alt='new'>")
}
}

Thanks for your time

djr33
03-17-2010, 05:59 AM
In general, using cookies for something means that you are not relying on them. Is it ok with you if only some visitors have this function working?

If you need something stable for everyone, you will need to use a serverside method and track users (by IP address? accounts?) in a database or text files.

If you are ok with the solution above, then someone can help you fix it-- but first be sure you want to attempt this using Javascript.

Beverleyh
03-17-2010, 12:30 PM
Yes, the js/cookie way is fine. Its not going to be used on anything critical as all that goes into newsletters and the official News & Updates page.

I just thought this would be a quick method to show some kind of immediate visual reference on the minor updates, but I think only having the "new" image show in the first page load is a little too quick ;)