How do I set/unset cookie with jQuery? -


How can I set and set cookies using jQuery, for example test Create a cookie and set the value to 1

View the plugin: < / P>

You can then:

  $ Cookie ("test", 1);   

To delete:

  $. Removecookie ("test");   

Additionally, to set a fixed amount of fixed days (10 here) on the cookie:

  $. Cookie ("test", 1, {expiration: 10});   

If the timeout option is omitted, the cookie becomes a session cookie, and the browser is deleted when exited.

To cover all options: $ The cookie ("test", 1, {expires: 10, // 10 day path is ending: '/', // the value of the path attribute of the cookie // (default: path of the cookie page) domain: 'Jquery.com', // the value of the domain's attribute of the cookie // (default: the domain of the page that creates the cookie): safe: true // If the cookie's safe feature is set / and cookie transmission / / Will need a secure protocol (default to false).});

To read the value of the cookie:

  var cookieValue = $ .cookie ("test");   

You would like to specify the path parameter, if the cookie was created on a different path than the current one:

  var cookieValue = $ .cookie ("test ", {Path: '/' Foo '});  Update (April 2015):   

As mentioned in the comments below, the team working on the original plugin has removed jquery dependency a new project () In which the same functionality and general syntax is as jquery version. Apparently the original plugin is not going anywhere.

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -