/ Published in: JavaScript
Expand |
Embed | Plain Text
setCookie: function ( id, value) { document.cookie = id+'='+value+';path=/;expires='+cookieTime(365); }, getCookie: function( id, defaultValue ) { var re = new RegExp(id+'=(.*)'); var value = re.exec(document.cookie); return (value) ? value[1].split(';')[0] : defaultValue; } function cookieTime(days){ var now = new Date(); var exp = new Date(); var x = Date.parse(now) + days*24*60*60*1000; exp.setTime(x); str = exp.toUTCString(); re = '/(\d\d)\s(\w\w\w)\s\d\d(\d\d))/'; return str.replace(re,"$1-$2-$3"); }
Comments
Subscribe to comments
You need to login to post a comment.

The regex for grabbing cookie data saved me about 10 lines of code.