:::: MENU ::::

How to manipulate cookie of array, object and json datatype using jQuery Plugins?


What’s Cookie

Cookie is small amount of key value based browser storage used to store tiny data on user’s browser by websites. It can be manipulated by javascript

Simple javascript code that manipulate cookie is

Cookie Plugins in jQuery

There are many jQuery plugins available to implement cookie easily with simple callbacks. That provides methods for add, remove or delete browser cookies.

List of Popular jQuery Cookies Plugins

Cookie manipulation with carhartl’s jQuery cookie plugin Plugin

  • Create session cookie that expires after user exits browser.

    Creating Cookie of string datatype

    Creating Cookie of array datatype

    Creating Cookie of json (object) datatype

  • Creating cookie that expires after specific time.

    String cookie with 5 days of expiry

    array cookie with 5 days of expiry

    object cookie with 5 days of expiry

  • More options

    How to set ssl (https) cookie with jQuery cookie plugin?

    How to set cross subdomain cookie with jQuery cookie plugin?


    Just prexif your domain value with dot (i.e. “.yourdomain.com”) in cookie option

    So above cookie is valid for all subdomain of site vikaskbh.com Check demo here

    Why & how to set cookie path with jQuery cookie plugin?

    path defines scope of cookie. By default, cookies are being set to directory structure of url. i.e. if you are accessing http://www.example.com/directory and try to set cookie, it will be set to /directory path. You could set it to root directory path “/” with cookie path option.

  • How to read cookie using jQuery plugin?

    Reading cookie is simple, just pass cookie key to $.cookie() function.

    Reading string cookie

    Reading array cookie

    Reading json cookie

  • How to delete cookie using jQuery plugin?

    To delete cookie, just use function $.removeCookie() and supply cookie key.

Cookie manipulation with Google code cookie plugin

  • Create cookie

    Simple string cookie

    JSON cookie

  • Read cookie

  • Delete cookie

So, what do you think ?