Set cookie to document and read it back
<HTML>
<HEAD>
<SCRIPT language="JavaScript">
function setCookie(){
var thename= "your name";
var the_text="name="+thename+"&";
var toexpire= new Date("March 31, 2010");
var expdate="expires="+toexpire.toGMTString();
the_text+=expdate;
var newtext=escape(the_text);
document.cookie=newtext;
var mycookie=document.cookie;
var fixed_cookie= unescape(mycookie);
var thepairs= fixed_cookie.split("&");
var pair1= thepairs[0];
var pair2= thepairs[1];
var namevalue= pair1.split("=");
window.alert("Welcome, "+namevalue[1]+"!");
}
setCookie();
</SCRIPT>
</HEAD>
<BODY>
text
</BODY>
</HTML>
Related examples in the same category