Update notifications cookie

32 views
Skip to first unread message

lauren...@free.fr

unread,
May 8, 2012, 6:35:49 AM5/8/12
to google-ap...@googlegroups.com
Hi.
I'm trying to set a cookie through javascript to show that one page (ie. the News page) have been updated within my website. This must be shown on every page of this website and should disappear only when the news page has been visited...
For now, i can make it work on every pages calling through an external js file, but the notification disappears when i visit ANY page, not only the News page. I want it to be a bit like facebook: Shows the notification as long as you haven't visited the right page.

Here is the code i have. How should i change it?

in the body of the page (calling the scripts):

<script type="text/javascript" src="newsupdate.js"></script><script type="text/javascript" src="newsupdatecall.js"></script>

File newsupdate.js:

now = new Date
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+1)
lastVisit = new Date(cookieVal("news"))
document.cookie = "news="+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 newChecknews(yyy,mm,dd) {
  lastChgd = new Date(yyy,mm-1,dd)
  if (lastChgd.getTime() > lastVisit.getTime()) {
    document.write("Page updated !!")
  }
}

File newsupdatecall.js :

newChecknews(2012,5,4)


I would like the cookie to be read on every pages of the website, showing "Page updated" beside the menu of News page, and disappear ONLY when News page have been visited... How should i do?
Thank you very much!!

Kyle Lemons

unread,
May 9, 2012, 12:06:25 PM5/9/12
to lauren...@free.fr, google-ap...@googlegroups.com
On Tue, May 8, 2012 at 3:35 AM, <lauren...@free.fr> wrote:
Hi.
I'm trying to set a cookie through javascript to show that one page (ie. the News page) have been updated within my website. This must be shown on every page of this website and should disappear only when the news page has been visited...
For now, i can make it work on every pages calling through an external js file, but the notification disappears when i visit ANY page, not only the News page. I want it to be a bit like facebook: Shows the notification as long as you haven't visited the right page.

Here is the code i have. How should i change it?

in the body of the page (calling the scripts):

<script type="text/javascript" src="newsupdate.js"></script><script type="text/javascript" src="newsupdatecall.js"></script>

File newsupdate.js:

now = new Date
expireDate = new Date
expireDate.setMonth(expireDate.getMonth()+1)
lastVisit = new Date(cookieVal("news"))
document.cookie = "news="+now+";expires=" + expireDate.toGMTString()

This sets the cookie, and is always included... so, it always gets set.
Reply all
Reply to author
Forward
0 new messages