Wednesday, April 1, 2009

How to set Javascript Cookie for Domain

var cookie_date = new Date ( ); // current date & time
cookie_date.setTime ( cookie_date.getTime() + 24*60*60*1000 ); // for 1 days


Syntax:
document.cookie = "CookieName=CookieValue; expires=cookie expire time"; path= directories;domain=domainname";

Example:
document.cookie="test=testValue;expires="+ cookie_date.toGMTString()+";path=/dir1/dir2/dir3/;domain=mytest.com";

No comments:

Post a Comment