Skip to content

Instantly share code, notes, and snippets.

@amitozdeol
Forked from bronson/cookie.js
Created December 27, 2018 16:24
Show Gist options
  • Save amitozdeol/32c266bf40543f521e8e69e202979496 to your computer and use it in GitHub Desktop.
Save amitozdeol/32c266bf40543f521e8e69e202979496 to your computer and use it in GitHub Desktop.
Read and write cookies from javascript. Small and simple.

To write JSON: $.cookie('name', JSON.stringify('data'))
And to read: $.parseJSON($.cookie('name'))

UTF8 characters cause some browsers to truncate the cookie string. Really irritating. Encoding in Base64 using http://code.google.com/p/javascriptbase64/ seems to fix it 100%.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment