Hi allUpon seeking to differentiate new content from old in an HTML list based upon when each user last visited, I began researching "new to you" functionality. It's used in several forums like Yabb to place a small graphic next to each newly-posted or updated link in the list, monitored by a cookie, then disappears after the link is clicked to indicate the topic has been read.
However, surprisingly there seems to be a dearth of demand for a script to do the same thing on plain old web pages. After extensive searching, only a single script seems to appear again and again for this purpose. Although it's concisely written, it doesn't have the necessary functionality as it is placed on the content page itself, not tied to the link that selects that page. So, for example, if three items in the list are new, that particular script tells them so, but then all three disappear when just one link is selected, because the script is actually telling the user that they have now visited the index page itself, not the particular article.
What I'm looking for is a way to tie the cookie to the HREF link, so it won't disappear until the link itself is clicked.
Wolfman
Here's that code. Notice that the BODY code specifies the date, which is compared by the script to the cookie's last recorded visit. So the desired change would be "how do I compare the date to the link's last recorded click?"
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'>")
}
}
Code:
<script type="text/javascript" language="JavaScript"> newCheck(2005,2,3)</script>
Comment