当前位置:网站首页>cookie增删改查方法
cookie增删改查方法
2022-07-26 23:18:00 【kilito_01】
/**
* 设置cookie
* @param {
*cookie名称} name
* @param {
*cookie值} value
*/
function setCookie(name, value, old_expires) {
var argv = arguments;
var argc = arguments.length;
var expires = (argc > 2) ? argv[2] : null;
if (expires != null) {
var LargeExpDate = new Date();
LargeExpDate.setTime(LargeExpDate.getTime() + (expires * 1000 * 3600 * 24));
}
document.cookie = name + "=" + escape(value) + ((expires == null) ? "" : (";path=/;expires=" + LargeExpDate.toGMTString()));
}
/**
* 读取cookie
* @param {
*cookie名称} Name
*/
function getCookie(Name) {
var search = Name + "="
if (document.cookie.length > 0) {
var offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length
var end = document.cookie.indexOf(";", offset)
if (end == -1) end = document.cookie.length
return unescape(document.cookie.substring(offset, end))
}
else return ""
}
}
/**
* 删除cookie
* @param {
*cookie名称} name
*/
function deleteCookie(name) {
var expdate = new Date();
expdate.setTime(expdate.getTime() - (86400 * 1000 * 1));
setCookie(name, "", expdate);
}
function clearCookie(){
var keys=document.cookie.match(/[^ =;]+(?=\=)/g);
if (keys) {
for (var i = keys.length; i--;)
document.cookie=keys[i]+'=0;expires=' + new Date( 0).toUTCString()
}
}
export {
setCookie, getCookie, deleteCookie,clearCookie }
边栏推荐
- Qt中文乱码常量换行符终极解决方案
- JMeter下载安装
- 证券公司哪家手续费最低?手机上开户安全吗
- Northeast Securities stock online account, is it safe to open an account on your mobile phone
- php+swoole
- Redis五种基本数据结构
- 通过ensp让静态路由实现全网可达
- [draw rectangular coordinate system in C language]
- Redis安装及运行(linux)
- Today, let's talk about escape characters [cute new version]
猜你喜欢

【用C语言绘制直角坐标系】

The latest multi-threaded & highly concurrent learning materials, interview confidence

After working in Tencent testing post for 5 years, I was ruthlessly dismissed in July, trying to wake up my brother who was still paddling

猜拳小程序 基于Object-C 新手上路

MGRE、PPP、HDLC综合实验

Record the nth SQL exception

BigDecimal 的 4 个坑,你踩过几个?
![[draw sherpinski triangle in C language]](/img/e6/9d1d088d1c7675c23725443000329b.png)
[draw sherpinski triangle in C language]

Hcip the next day

Static routing experiment configuration
随机推荐
BigDecimal 的 4 个坑,你踩过几个?
【在Visual Studio 2019中使用SQLite3库实现学生信息管理系统】
LeetCode->二分法(三)
HCIP-第六天-OSPF静态大实验
NAT网络地址转化实验
[draw sherpinski triangle in C language]
Record the nth SQL exception
多线程的具体使用
HCIP-第五天-OSPF扩展配置实验
go语言慢速入门——包
Constant knowledge explanation of C language
HCIP-第三天-广域网拓扑实验
Hcip day 3 Wan topology experiment
The XML format of labelimg annotation is converted to yolov5
Is it necessary to open an account on site for securities speculation? Is it safe to open an account online
[brother Yang takes you to play with the linear table (4) - chain queue]
Prometheus operation and maintenance tool promtool (III) debug function
oSPF基础实验配置
Prometheus 运维工具 Promtool (三) Debug 功能
Interesting C language