LinkExchange
TopLinkExchange Member
Client side update tracking

The script implemented into this page allows visitor to know if page was updated since his last visit. Client side cookies mechanism was used to keep information on last visited revision of page. To see the use of this script browse my site. I am going to implement this script into most of my pages.

To use this script on your page do the following:

  1. Insert script into the HEAD of your page document:
    
    <HEAD>
    ....
    <SCRIPT LANGUAGE="JavaScript">
    <!--
    
    var cookiename="update_filename";   //change this value!!!!
    
    function getCookie(c_name)  //my cookie functions; use the if you like them
      {
      c_string=c_name+"="; 
      if(document.cookie.indexOf(c_string)==-1)
       {return "";}
      strbegin = (document.cookie.indexOf(c_string)+c_string.length);
      strend = document.cookie.indexOf(";", strbegin);
      if (strend == -1) 
       {strend = document.cookie.length;}
      return (unescape(document.cookie.substring(strbegin, strend)));
      }
    function setCookie(c_name,value,exp)
     {
      c_string=c_name+"="; 
      document.cookie=c_string + escape(value)+"; expires=" + exp.toGMTString();    //add new property
     }
    function removeCookie(c_name)
     {
     setCookie(c_name,"",new Date(0));
     }
    
    function checkUpdate()  //Update check function
     {
    	var exp=new Date();                //get current date
    	var plusoneyear=exp.getTime()+(365 * 24 * 60 * 60 * 1000); // add one year 
    	exp.setTime(plusoneyear);          //put result to exp (cookie will expire in a year)
    	var last=getCookie(cookiename);  //get last seen revision of document
    	var str=document.lastModified;     //get last revision of document
    	// Parse last revision into Date structure
    	var update=new Date(str.substring(6,8),str.substring(0,2),str.substring(3,5),str.substring(9,11),str.substring(12,14),str.substring(15,17));
    	
    	if(last!=0)   // page had been visited before
    	 {
    	 if(update.getTime()>last)     // page updated
    	  {  // Inform user about page update by means of alert window.
    	     // (You may change this behaviour by substituting line below.)
    	  window.alert("This page had been updated since you last visit!");
    	  }
    	 }
    	else  		   // the very first visit to this page
    	   {  // Greet user by means of alert window.
    	      // (You may change this behaviour by substituting line below.)
    	   window.alert("Welcome to "+document.title);  
    	   }
    	
    	setCookie(cookiename,update.getTime(),exp);  // set new last seen revision date cookie
      }
    //-->
    </SCRIPT>
    ....
    </HEAD>
    
    
  2. Change the value of cookiename to "update_filename" ( or any other unique string )
    Here is what I use in this file:
    var cookiename="update_trackup";
  3. Insert onLoad option into BODY TAG:
    <BODY ... onLoad="checkUpdate();" ... >

The general idea of script above is to compare last revision date saved in client cookie to the actual last revision date.

For more information on persistent cookie mechanism you may refer to the article in ViewSource Magazine: JavaScript Cookie Recipes


Back to the Main Page
If you have any questions or comments, check out my FAQ


Guestbook by Lpage Sign My Guestbook
View My Guestbook
Enhanced For Netscape Navigator.
Download Netscape Now!


Designed & Posted by Java Solutions Inc. , if you have any suggestions, comments, complains, E-mail WebMaster.Copyright © 1997,1998. All rights reserved. .
1