Making a Smart What's New Section

Have you ever noticed that the stuff in people's What's New areas aren't really that new to you? Wouldn't it be cool if you went to a page and it would only tell you the new stuff since the last time you've been there? It can be done with javascript and cookies.

Here's how it would work. Every time someone comes to your page, you send them a cookie containing a number. You start out sending people zeros. When you update the page, you change it to send ones, then twos etc. This way, all you have to do is read the cookie from them when the page first starts up, and you'll know what the page was like the last time that person was there.

Did you understand that? Lets have an example. Lets say theres a brand new page using this technique. You go to this page and it reads the cookie from you. It reads null because you don't have it yet. It then writes a 0 to the cookie. The next day, the page is updated and you return to it. The javascript code has also been updated to give out ones now. When the page loads, it reads the cookie from you. Since you still have a 0, it knows that you don't know about the new stuff and it puts it in the What's New section. It then updates your cookie to be a one. If you return latter and the page hasn't changed at all then it will read your cookie, see that it is a one, compair it to the cookie its giving out, and see that they are the same. It decides not to tell you about the new stuff because it knows it already told you before. If you come back in a month and it is giving out twenties now, then it knows there have been alot of changes since you've been there and it tell you about them. Then it updates your cookie to a twenty. Get it?

Assuming you have a GetCookie() fnction and a SetCookie() function, your code would be somthing like this:

New or changed code in green.
Unchanged code in gray.
var temp = GetCookie("update");
if (temp==null) {
	document.write("You're new here, aren't ya? Welcome to my page!");
	}
SetCookie("update",0);

Then after you update your page, you change the code a bit:

var temp = GetCookie("update");
if (temp==null) {
	document.write("You're new here, aren't ya? Welcome to my page!");
	}

if (temp<1) {
	document.write("Check out our new joke section!");
	}

SetCookie("update",1);

If you update it again:

var temp = GetCookie("update");
if (temp==null) {
	document.write("You're new here, aren't ya? Welcome to my page!");
	}

if (temp<2) {
	document.write("We have a new movie section!");
	}

if (temp<1) {
	document.write("Check out our new joke section!");
	}
SetCookie("update",2);