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

https://stackoverflow.com/questions/15932957/difference-between-0-and-negative-value-for-setmaxage-for-cookie

Setting setMaxAge to 0 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

最新文章

  1. 自制jquery可编辑的下拉框
  2. Web Components之Custom Elements
  3. php源码编译常见错误解决方案
  4. Embedded System.
  5. ThinkPHP接入支付宝支付功能
  6. c-连接两个链表
  7. hdu How many integers can you find
  8. Swift - 实现拨打电话
  9. Objective-C之成魔之路【9-类构造方法和成员变量作用域、以及变量】
  10. windows Azure平台开发
  11. 实现javascript下的模块组织
  12. Web 小案例 -- 网上书城(三)
  13. 【Unity与23种设计模式】装饰模式(Decorator)
  14. PyCharm更换sublime类似主题
  15. 【python路飞】编码 ascii码(256位 =1个字节)美国;unicode(万国码)中文 一共9万个 用4个字节表示这9万个子 17位就能表示
  16. tkinter中combobox下拉选择控件(九)
  17. Golang初练手-多线程网站路径爆破
  18. python之路——4
  19. list集合去除重复对象的实现
  20. 高并发中nginx较优的配置

热门文章

  1. Mybatis参数预编译
  2. B树、B+树索引算法原理(下)
  3. 干货 | 高耦合场景下,Trip.com如何做支付设计与落地
  4. 排查golang的性能问题 go pprof 实践
  5. LOJ10162 骑士
  6. PIGS_POJ1149
  7. 济南学习D3T1__线性筛和阶乘质因数分解
  8. 最简单直接地理解Java软件设计原则之单一职责原则
  9. 七:Spring Security 前后端分离登录,非法请求直接返回 JSON
  10. 五:SpringBoot-多个拦截器配置和使用场景