From 4b6c0e31385f5f27a151088c0a2b614495c4e589 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Thu, 14 Oct 2021 12:47:50 -0400 Subject: initial commit, including theme --- ...sycookie-easy-javascript-cookie-management.html | 83 ++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 content/posts/2007-10-17-easycookie-easy-javascript-cookie-management.html (limited to 'content/posts/2007-10-17-easycookie-easy-javascript-cookie-management.html') diff --git a/content/posts/2007-10-17-easycookie-easy-javascript-cookie-management.html b/content/posts/2007-10-17-easycookie-easy-javascript-cookie-management.html new file mode 100644 index 0000000..1fcc015 --- /dev/null +++ b/content/posts/2007-10-17-easycookie-easy-javascript-cookie-management.html @@ -0,0 +1,83 @@ +--- +date: "2007-10-17T02:28:43Z" +title: 'EasyCookie: Easy Javascript Cookie Management' +--- + +

Ever tried to read and write cookies in Javascript? If you have, then +I'll wait until you've stopped frothing at the mouth and +pounding your keyboard.

+ +

...

+ +

Feeling better? Good. I just released the first public version of +EasyCookie, a simple cookie library for Javascript. Using +EasyCookie is, well, easy. For example, here's how you get a cookie:

+ +
// get a cookie
+val = EasyCookie.get('my_cookie');
+
+ +

And here's how you set one:

+ +
// set a cookie
+val = 'a random value that i want to save as a cookie';
+EasyCookie.set('my_cookie', val);
+
+ +

And, if you haven't already guessed, here's how your remove a cookie:

+ +
// remove a cookie
+EasyCookie.remove('my_cookie');
+
+ +

But what about all the extra crap you usually have to fight to get +working, like the domain, path, and expiration? Don't panic! +EasyCookie.set takes a hash of additional attributes as an optional +third argument. Here's another example of EasyCookie.set, this time +with the optional hash:

+ +
// value to set
+val = '99 bottles of beer on the wall, 99 bottles of beer!';
+
+// set a cookie that expires in 10 days, and limit the scope to
+// "https://foo.example.com/some/path"
+EasyCookie.set('my_cookie', val, {
+  // expires in 10 days
+  expires: 10,
+
+  // limit cookie to domain 'foo.example.com'
+  domain: 'foo.example.com',
+
+  // limit cookie to path '/some/path'
+  path: '/some/path',
+
+  // restrict cookie to secure pages only
+  secure: true
+});
+
+ +

Checking to see if cookies are enabled just got a whole lot simpler, +too:

+ +
// are cookies enabled?
+enabled = EasyCookie.enabled;
+
+// harass user with annoying dialog about their cookie status
+alert('Cookies are ' + (enabled ? 'enabled' : 'not enabled'));
+
+ +

Best of all, EasyCookie is BSD licensed, and the minified +version weighs in at a measly 1873 bytes. Anyway, here ya go:

+ + + +

+ PS. Yes, I realize the link above are to version 0.2.1 of EasyCookie, + even though this is the first public release. In internet years the + backend to my page is older than your grandmother. Imagine trying to + explain how to release software to your grandmother. +

+ -- cgit v1.2.3