cookie.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. var today = new Date();
  2. var expiryyear = new Date(today.getTime() + 365 * 24 * 60 * 60 * 1000);
  3. var expirymonth = new Date(today.getTime() + 30 * 24 * 60 * 60 * 1000);
  4. var expiryday = new Date(today.getTime() + 24 * 60 * 60 * 1000);
  5. function getCookie(name)
  6. {
  7. var reg= new RegExp("; "+name+";|; "+name+"=([^;]*)");
  8. var matches=reg.exec('; '+document.cookie+';');
  9. if (matches) return ((matches[1])?unescape(matches[1]):'');
  10. return null;
  11. }
  12. function setCookie (name,value,expires,path,domain,secure)
  13. {
  14. document.cookie = name + "=" + escape (value) +
  15. ((expires) ? "; expires=" + expires.toGMTString() : "") +
  16. ((path) ? "; path=" + path : "") +
  17. ((domain) ? "; domain=" + domain : "") +
  18. ((secure) ? "; secure" : "");
  19. return getCookie(name)!=null?true:false;
  20. }
  21. function deleteCookie (name,path,domain)
  22. {
  23. if (getCookie(name)!=null)
  24. {
  25. document.cookie = name + "=" +
  26. ((path) ? "; path=" + path : "") +
  27. ((domain) ? "; domain=" + domain : "") +
  28. "; expires=Thu, 01-Jan-1970 00:00:01 GMT";
  29. }
  30. }
  31. function cookieEnabled()
  32. {
  33. testCookieName="_testCookie_";
  34. if (setCookie(testCookieName,1))
  35. {
  36. deleteCookie(testCookieName);
  37. return true;
  38. }
  39. else return false;
  40. }