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:
<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>
Sign My Guestbook View My Guestbook |
Enhanced For Netscape Navigator. Download Netscape Now! |