当前位置:网站首页>Cookie addition, deletion, modification and query methods
Cookie addition, deletion, modification and query methods
2022-07-27 02:43:00 【kilito_ 01】
/**
* Set up cookie
* @param {
*cookie name } name
* @param {
*cookie value } 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()));
}
/**
* Read cookie
* @param {
*cookie name } 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 ""
}
}
/**
* Delete cookie
* @param {
*cookie name } 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 }
边栏推荐
猜你喜欢

【Redis】五种常用的数据类型

【用C语言绘制谢尔宾斯基三角形】

White box test case design (my grandfather can understand it)

【自此文之后,学习链表一片坦途】

Prompt to leave the page

How many holes have you stepped on in BigDecimal?

30岁被裁,我想明白的几件事....

【斐波那契数列及螺线 基于C语言】

Record the star user of handsomeblog
![[brother Yang takes you to play with the linear table (4) - chain queue]](/img/b6/ea76e060be73bc14f2166144e7b5e7.png)
[brother Yang takes you to play with the linear table (4) - chain queue]
随机推荐
[enchanting interpretation, 15 minutes let you thoroughly learn how to use the stack!!!]
OSPF summary (mind map)
创业3年,现在鹅厂,年收入百万+,作为软件测试前辈的一些建议....
Witness that the "decoding 2022 strong star of China's network security" is about to set sail
LeetCode刷题——NO.238——除自身以外数组的乘积
30岁被裁,我想明白的几件事....
Solve every bit of an integer
信息收集-端口扫描工具-Nmap使用说明
hcip--ospf接口网络接口类型实验
Qt中文乱码常量换行符终极解决方案
Functions of libraries and Archives
什么是进程?
com.fasterxml.jackson.databind.exc.InvalidDefinitionException
在腾讯测试岗干了5年,7月无情被辞,想给还在划水的兄弟提个醒.....
f8抓交通、f9抓兔子、f10turtle
pyqt5使用pyqtgraph画动态散点图
【无标题】
bp 插件临时代码记录
想要彻底搞的性能优化,得先从底层逻辑开始了解~
解决小程序报错getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json