当前位置:网站首页>Is the cookie valid for a limited time? How to set cookies? Teach you to set by hand
Is the cookie valid for a limited time? How to set cookies? Teach you to set by hand
2022-07-19 05:26:00 【In the past_ juvenile】
1.cookie Is there a valid time limit ?
cookie There is a valid time , And you can customize the effective time
2. How to set up cookie?
Here I directly encapsulate , Post code directly , If you don't understand, you can send a private message !!!
// Set up cookie
static setCookie(key, value, expiremHours) {
var exdate = new Date();
exdate.setTime(exdate.getTime() + expiremHours * 60 * 60 * 1000);
document.cookie =
key +
"=" +
escape(value) +
(expiremHours == null ? "" : ";expires=" + exdate.toUTCString());
}
// Read cookie
static getCookie(key) {
if (document.cookie.length > 0) {
var c_start = document.cookie.indexOf(key + "=");
if (c_start != -1) {
c_start = c_start + key.length + 1;
var c_end = document.cookie.indexOf(";", c_start);
if (c_end == -1) c_end = document.cookie.length;
return unescape(document.cookie.substring(c_start, c_end));
}
}
return "";
}
// Delete cookie
static delCookie(key) {
var exp = new Date();
exp.setTime(exp.getTime() - 1);
var cval = this.getCookie(key);
if (cval != null) {
document.cookie = key + "=" + cval + ";expires=" + exp.toUTCString();
}
}
// throttle
static throttle(callBack, time) {
let timer = null;
//timer State to be resident in memory , Here is a closure
return function() {
if (!timer) {
timer = setTimeout(() => {
callBack();
timer = null;
}, time);
}
};
}
边栏推荐
猜你喜欢
随机推荐
Redis 源码分析-数据结构及实现(字典dict)
软件测试就业前景怎样 人才需求大,岗位稳定性强
面试官:大量请求 Redis 不存在的数据,从而影响数据库,该如何解决?
2022年春招最新消息:IT互联网行业平均薪资18500元
ambari集群扩容节点+扩容服务操作
聊聊redis分布式锁的8大坑
BUUCTF 杂项——二维码
Markdown notes and related shortcut keys of typora
Data visualization
第一个智能合约程序Faucet.sol
Redis source code analysis - data structure and Implementation (Dictionary dict)
聊聊写代码的20个反面教材
What is the employment prospect of software testing? There is a large demand for talents and strong job stability
RK356x U-Boot研究所(命令篇)3.4 mem内存相关命令的用法
Easypoi excel simple export
Talk about 12 business scenarios of concurrent programming
Mapbox loads local offline terrain
Shell脚本配置root免密登录到其他主机
Swagger配置与使用
线上软件测试培训机构柠檬班与iTest.AI平台达成战略合作









