Skip to content

Instantly share code, notes, and snippets.

@evolutionxbox
Last active June 7, 2016 16:29
Show Gist options
  • Save evolutionxbox/45b54348838f6daed2fd2213f3b52f18 to your computer and use it in GitHub Desktop.
Save evolutionxbox/45b54348838f6daed2fd2213f3b52f18 to your computer and use it in GitHub Desktop.
document.cookies returns an object containing key value pairs of all the document's cookies.
// document.cookies
// getter property accessor
// returns Object
//
// Examples:
// var cookies = document.cookies;
// var mycookie = document.cookies.mycookie;
if (typeof Document.prototype.cookies == 'undefined') {
Object.defineProperty(Document.prototype, "cookies", {
get: function () {
var object = {};
document.cookie.split(';').forEach(function (item) {
var regexp = new RegExp("^ ?(.+?)=(.*?)$");
var result = regexp.exec(item);
result && (object[result[1]] = result[2]);
});
return object;
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment