Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

jQuery cookie plugin for storing/retrieving JSON

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 external
Octocat-spinner-32 test
Octocat-spinner-32 GPL-LICENSE.txt
Octocat-spinner-32 MIT-LICENSE.txt
Octocat-spinner-32 jquery.jsoncookie.js
Octocat-spinner-32 readme.md
readme.md

jQuery JSON Cookie

Cookies are the most widely available form of persistent client-side storage. Unfortunately there's no built-in support for storing structured data inside of one. That's where the jsoncookie plugin comes in; this plugin allows you to store any data that can be represented via JSON. This means that you can store objects, arrays, strings, numbers, and booleans and get the data back exactly as you expect. (Standard cookie size limitations of 4K still exist)

Usage

$.cookie( string key, mixed value [, hash options ] )

Stores a value for a given key.

  • key: Identifier for the value being stored.
  • value: The value to store. The value can be anything that can be serialized as JSON.
  • [options]: A set of key/value pairs that relate to settings for storing the value (see Options section below).

 

$.cookie( string key )

Gets a stored value based on the key.

$.cookie()

Gets a hash of all stored values.

Options

  • expires Duration in milliseconds that the cookie should exist.
  • domain Limit which pages can access the cookie based on the (sub)domain. Defaults to the current domain.
  • path Limit which pages can access the cookie based on the path. Defaulst to the current path.
  • secure Boolean. Whether to limit the cookie to only be sent over secure connections.

This plugin requires the JSON object to exist. For support in older browsers, you'll need to include json2.js.

For more information on cookies, see the MDN documentation.

Chrome doesn't support cookies for local files unless you start it with the --enable-file-cookies flag.

Something went wrong with that request. Please try again.