/[webpac]/trunk2/out/js/cookies.js
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Annotation of /trunk2/out/js/cookies.js

Parent Directory Parent Directory | Revision Log Revision Log


Revision 554 - (hide annotations)
Fri Oct 29 22:05:51 2004 UTC (19 years, 7 months ago) by dpavlin
File MIME type: application/javascript
File size: 983 byte(s)
Return empty string and not null when cookie doesn't exits. This can be
changed back to null by changing one comment. This is much more useful if
you want to insert cookie value into input text element with
document.write();

1 dpavlin 514 function get_cookie(name) {
2 dpavlin 554 var no_val = '';
3     // uncomment following line to get old behaviour null on no cookie
4     //no_val = null;
5    
6 dpavlin 514 var start = document.cookie.indexOf(name+"=");
7     var len = start+name.length+1;
8 dpavlin 554 if ((!start) && (name != document.cookie.substring(0,name.length))) return no_val;
9     if (start == -1) return no_val;
10 dpavlin 514 var end = document.cookie.indexOf(";",len);
11     if (end == -1) end = document.cookie.length;
12     return unescape(document.cookie.substring(len,end));
13     }
14    
15     function set_cookie(name,value,expires,path,domain,secure) {
16     document.cookie = name + "=" +escape(value) +
17     ( (expires) ? ";expires=" + expires.toGMTString() : "") +
18     ( (path) ? ";path=" + path : "") +
19     ( (domain) ? ";domain=" + domain : "") +
20     ( (secure) ? ";secure" : "");
21     }
22    
23     function delete_cookie(name,path,domain) {
24     if (get_cookie(name)) document.cookie = name + "=" +
25     ( (path) ? ";path=" + path : "") +
26     ( (domain) ? ";domain=" + domain : "") +
27     ";expires=Thu, 01-Jan-70 00:00:01 GMT";
28     }

  ViewVC Help
Powered by ViewVC 1.1.26