-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Frequently Asked Questions
Reference version: 2.0.4
JavaScript Cookie supports a Date instance to be passed in the expires attribute. That provides a lot of flexibility since a Date instance can specify any moment in time.
Take for example, when you want the cookie to expire 15 minutes from now:
var inFifteenMinutes = new Date(new Date().getTime() + 15 * 60 * 1000);
Cookies.set('foo', 'bar', {
expires: inFifteenMinutes
});
Also, you can specify fractions to expire in half a day (12 hours):
var inHalfADay = 0.5;
Cookies.set('foo', 'bar', {
expires: inHalfADay
});
Or in 30 minutes:
var in30Minutes = 1/48;
Cookies.set('foo', 'bar', {
expires: in30Minutes
});
It's not possible to remove literally all cookies from the user's browser. Some of them might have been created with a separate domain
or path
attribute than the one the user is currently in or even created with the httpOnly
attribute and therefore they might not be visible.
What it's possible is to try to remove all cookies that are visible to the user:
Object.keys(Cookies.get()).forEach(function(cookieName) {
var neededAttributes = {
// Here you pass the same attributes that were used when the cookie was created
// and are required when removing the cookie
};
Cookies.remove(cookieName, neededAttributes);
});
js-cookie does not have an easy way to add plugins or to extend any of its functionality. And that's by design.
See this for additional information and why.
Return to Wiki Home-Page Return to General Home-Page