cookie & maxAge & expires
2024-08-30 03:47:19
cookie & maxAge & expires
Expires (timestamp) & Max-Age (seconds)
https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Set-Cookie
cookie demo
create & delete
https://codepen.io/webgeeker/full/vaQRqe/
setTimeout(() => {
let btn = document.querySelector(`[data-link="logout"]`);
btn.addEventListener(`click`, function (e) {
// clear cookie
document.cookie = "access_token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;";
setTimeout(() => {
window.parent.location.replace(`http://10.1.5.202/auto-deploy-platform/login/index.html`);
}, 0);
});
}, 1000);
// obj = {key: "", value: "", timestamp: 36*Math.pow(10, 6)};// one day & ms
// {key: "", value: "", timestamp: 36000000}
/*
new Date(new Date().getTime() + 36000*1000).toUTCString();
"Thu, 09 Aug 2018 13:44:09 GMT"
new Date().toUTCString();
"Thu, 09 Aug 2018 03:44:15 GMT"
*/
let ga = {
key: "_ga",
value: "GA1.2.156580446.1505450776",
timestamp: 36*Math.pow(10, 6)
};
// one day & ms
const setCookie = (obj = {key: "", value: "", timestamp: 36000*1000}, debug = false) => {
let {
key,
value,
timestamp
} = obj;
let host = window.parent.location.origin;
if(key && value) {
// let expires = new Date().toUTCString();
let expires = new Date(new Date().getTime() + 36000*1000).toUTCString();
let domain = host.includes(`https`) ? host.slice(8) : host.slice(7);
document.cookie = `${key}=${value}; expires=${expires}; path=/; domain=${domain};`;
}
};
setCookie(ga);
const deleteCookie = (key = ``, debug = false) => {
let host = window.parent.location.origin;
if(key) {
let expires = new Date("1969-01-01").toUTCString();
let domain = host.includes(`https`) ? host.slice(8) : host.slice(7);
document.cookie = `${key}=; expires=${expires}; path=/; domain=${domain};`;
}
};
deleteCookie(ga.key);
setMaxAge
Setting
setMaxAge
to0
will delete the cookie.
Setting
setMaxAge
to-1
will preserve it until the browser is closed.
CORS & cookie
https://www.cnblogs.com/xgqfrms/p/9198180.html
最新文章
- 自制jquery可编辑的下拉框
- Web Components之Custom Elements
- php源码编译常见错误解决方案
- Embedded System.
- ThinkPHP接入支付宝支付功能
- c-连接两个链表
- hdu How many integers can you find
- Swift - 实现拨打电话
- Objective-C之成魔之路【9-类构造方法和成员变量作用域、以及变量】
- windows Azure平台开发
- 实现javascript下的模块组织
- Web 小案例 -- 网上书城(三)
- 【Unity与23种设计模式】装饰模式(Decorator)
- PyCharm更换sublime类似主题
- 【python路飞】编码 ascii码(256位 =1个字节)美国;unicode(万国码)中文 一共9万个 用4个字节表示这9万个子 17位就能表示
- tkinter中combobox下拉选择控件(九)
- Golang初练手-多线程网站路径爆破
- python之路——4
- list集合去除重复对象的实现
- 高并发中nginx较优的配置