Connecting Tech Pros Worldwide Forums | Help | Site Map

New to Javascript, help with expiring cookies

Newbie
 
Join Date: May 2007
Location: SCV
Posts: 1
#1: May 28 '07
I get java errors in IE with this cookie, any idea why? Also how do I name the cookie and set it to expire in 20 min. I am not that familiar with expiring cookies. Any help is appreciated.



Expand|Select|Wrap|Line Numbers
  1. function setCookie(name, value, expires, path, domain, secure)
  2. {
  3.     document.cookie= name + "=" + escape(value) +
  4.         ((expires) ? "; expires=" + expires.toGMTString() : "") +
  5.         ((path) ? "; path=" + path : "") +
  6.         ((domain) ? "; domain=" + domain : "") +
  7.         ((secure) ? "; secure" : "");
  8. }
  9.  
  10.  
  11. function getCookie(name)
  12. {
  13.     var dc = document.cookie;
  14.     var prefix = name + "=";
  15.     var begin = dc.indexOf("; " + prefix);
  16.     if (begin == -1)
  17.     {
  18.         begin = dc.indexOf(prefix);
  19.         if (begin != 0) return null;
  20.     }
  21.     else
  22.     {
  23.         begin += 2;
  24.     }
  25.     var end = document.cookie.indexOf(";", begin);
  26.     if (end == -1)
  27.     {
  28.         end = dc.length;
  29.     }
  30.     return unescape(dc.substring(begin + prefix.length, end));
  31. }
  32.  
  33.  
  34. function deleteCookie(name, path, domain)
  35. {
  36.     if (getCookie(name))
  37.     {
  38.         document.cookie = name + "=" + 
  39.             ((path) ? "; path=" + path : "") +
  40.             ((domain) ? "; domain=" + domain : "") +
  41.             "; expires=Thu, 01-Jan-70 00:30:01 GMT";
  42.     }
  43. }

pbmods's Avatar
Site Moderator
 
Join Date: Apr 2007
Location: Texas
Posts: 5,435
#2: May 28 '07

re: New to Javascript, help with expiring cookies


Heya, chrisx. Welcome to TSDN!

Quote:

Originally Posted by chrisx

I get java errors in IE with this cookie, any idea why?

Because you're doing something wrong. If you want a better answer, it might be helpful if you posted WHAT errors you're getting o_O
Reply