<html> <head> <script> function getCookie(cookieName) { var cookieValue=""; var beginIndex=0; var endIndex=0; var cookies=document.cookie; if (cookies.length >0) { beginIndex=cookies.indexOf(cookieName+"="); if (beginIndex !=-1) { beginIndex +=cookieName.length+1; endIndex=cookies.indexOf(";", beginIndex); //if it the last cookie if (endIndex == -1) endIndex=cookies.length; cookieValue=unescape(cookies.substring(beginIndex,endIndex)); } } return cookieValue; } alert("cookie1=#"+getCookie("cookie1")+"#"); alert("cookie2=#"+getCookie("cookie2")+"#"); alert("undefined cookie=#"+getCookie("cookie3")+"#"); </script> </head> <body> <a href="setcookie.html">set cookie1</a><br> <a href="setcookie2.html">set cookie2</a><br> <a href="overrideCookie.html">override cookie1</a><br> </body> </html>