Setting a cookie with jQuery is as simple as this, where a cookie is created called "example" with a value of "foo": $. cookie("example", "foo"); This is a session cookie which is set for the current path level and will be destroyed when the user exits the browser.
To delete a cookie with JQuery, set the value to null: $. cookie("name", null, { path: '/' });
Use JavaScript Cookie plugin
Cookies.set("example", "foo"); // Sample 1
Cookies.set("example", "foo", { expires: 7 }); // Sample 2
Cookies.set("example", "foo", { path: '/admin', expires: 7 }); // Sample 3
alert( Cookies.get("example") );
Cookies.remove("example");
Cookies.remove('example', { path: '/admin' }) // Must specify path if used when setting.
As I know, there is no direct support, but you can use plain-ol' javascript for that:
// Cookies
function createCookie(name, value, days) {
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
var expires = "; expires=" + date.toGMTString();
}
else var expires = "";
document.cookie = name + "=" + value + expires + "; path=/";
}
function readCookie(name) {
var nameEQ = name + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
}
return null;
}
function eraseCookie(name) {
createCookie(name, "", -1);
}
Use jquery cookie plugin, the link as working today: https://github.com/js-cookie/js-cookie
Google is my friend and it showed me this page:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With