JAVASCRIPT
Cookie Utilities
All samples are using Ink.requireModules
, please read how to use it at Ink.requireModules section
Function name | Description |
---|---|
.get([name]) | Gets an object with the current page cookies, or a specific cookie if you specify the name . |
.remove(cookieName, [path], [domain]) | Deletes a cookie. |
.set(name, value, [expires], [path], [domain], [secure]) | Sets a cookie. |
Gets an object with the current page cookies, or a specific cookie if you specify the name
.
name
The cookie name.Code
Ink.requireModules(['Ink.Util.Cookie_1'], function( InkCookie ){
var cookie = InkCookie.get('inkcookie');
Ink.log(cookie);
// one_day_ttl
var oCookies = InkCookie.get();
Ink.log(oCookies);
// {inkcookie: "one_day_ttl"}
var cookie2 = InkCookie.get('foobar');
Ink.log(cookie2);
// null
});
Deletes a cookie.
cookieName
Cookie name.path
Path of the cookie. Defaults to '/'.domain
Domain of the cookie. Defaults to current hostname.Code
Ink.requireModules(['Ink.Util.Cookie_1'], function(InkCookie) {
InkCookie.remove('inkcookie');
});
Remove a cookie setted with path and domain
Code
Ink.requireModules(['Ink.Util.Cookie_1'], function(InkCookie) {
InkCookie.remove('inkcookie', '/', '.topdomain.com');
});
Sets a cookie.
name
Cookie name.value
Cookie value.expires
Number of seconds the cookie will be valid for.path
Path for the cookie. Defaults to '/'.domain
Domain for the cookie. Defaults to current hostname.secure
Flag for secure. Default 'false'.Set a cookie that expires in one day
Code
Ink.requireModules(['Ink.Util.Cookie_1'], function( InkCookie ){
InkCookie.set( 'inkcookie', 'one_day_ttl', (60 * 60 * 24));
});
Set a session cookie
in path /
of top damain
Code
Ink.requireModules(['Ink.Util.Cookie_1'], function( InkCookie ){
InkCookie.set( 'inkcookie', 'one_day_ttl', 0, '/', '.topdomain.com');
});