Store/Retrieve/Verify/Replace/Remove JSON In Cookies - jQuery SuperCookie

Store/Retrieve/Verify/Replace/Remove JSON In Cookies - jQuery SuperCookie

SuperCookie is a jQuery cookie manipulation plugin for JSON that allows you to write, read, verify, replace, delete JSON data in Cookies.

1. Load the needed jQuery library, jQuery cookie plugin, and JSON3 in the html document.

<script src="/path/to/jquery.min.js"></script>
<script src="/path/to/jquery.min.js"></script>
<script src="/path/to/jquery.min.js"></script>

2. Download and load the SuperCookie in the document.

<script src="/path/to/jquery.SuperCookie.min.js"></script>

3. Store JSON values in the cookies.

$.super_cookie({
  expires: 7,
  path: "/",
  // more jquey.cookie plugin options
})
.create("Cookie-Name",{
  name_field_1:"value1",
  name_field_2:"value2",
  // more values here
});

4. Check if cookie exists.

$.super_cookie().check("Cookie-Name")

5. Verify cookie values.

$.super_cookie().verify("Cookie-Name")

6. Read cookie values.

$.super_cookie().read_values("Cookie-Name")

7. Retrieve cookie values as a JSON object.

$.super_cookie().read_JSON("Cookie-Name")

8. Retrieve a single cookie value.

$.super_cookie().read_value("Cookie-Name","name_field_21")

9. Replace a cookie value.

$.super_cookie().replace_value("Cookie-Name","name_field_2","new_value");

10. Add a new cookie value.

$.super_cookie().add_value("Cookie-Name","name_field_3","value3");

11. Remove a cookie value.

$.super_cookie().remove_value("Cookie-Name","name_field_3");

This awesome jQuery plugin is developed by tantau-horia. For more Advanced Usages, please check the demo page or visit the official website.

  • Publication date: 01.06.2018
  • Source