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
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