Skip to content

Instantly share code, notes, and snippets.

@bronson
Last active March 26, 2022 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save bronson/6707533 to your computer and use it in GitHub Desktop.
Save bronson/6707533 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