Published in: JavaScript
URL: http://jsfromhell.com/geral/cookie
Object to manage cookies. Created: 2006.04.24
/************************************** * Jonas Raoni Soares Silva * http://www.joninhas.ath.cx **************************************/ Cookie = { isSupported: function(){ var s = "{3F2504E0-4F89-11D3-9A0C-0305E82C3301}"; return "cookie" in document && this.write(s, "OK") && this.read(s) == "OK" && this.remove(s); }, exists: function(name){ return document.cookie.indexOf(name + "=") + 1; }, write: function(name, value, expires, path, domain, secure) { expires instanceof Date ? expires = expires.toGMTString() : typeof(expires) == 'number' && (expires = (new Date(+(new Date) + expires * 1e3)).toGMTString()); var r = [name + "=" + escape(value)], s, i; for(i in s = {expires: expires, path: path, domain: domain}) s[i] && r.push(i + "=" + s[i]); return secure && r.push("secure"), document.cookie = r.join(";"), true; }, read: function(name){ var c = document.cookie, s = this.exists(name), e; return s ? unescape(c.substring(s += name.length, (c.indexOf(";", s) + 1 || c.length + 1) - 1)) : ""; }, remove: function(name, path, domain){ return this.exists(name) && this.write(name, "", new Date(0), path, domain); } };
You need to login to post a comment.
