当前位置:网站首页>解决IE7 & IE8 存储cookie问题
解决IE7 & IE8 存储cookie问题
2022-07-26 09:25:00 【乌云乌云_快走开】
解决IE7 & IE8 存储cookie问题
最近在做一个项目,需要兼容比较低版本的浏览器,现在竟然还有人用xp系统的IE7 !!!!听到这个消息的时候我整个人都不好了。
其中某个功能需要用cookie存储和清除,发现在ie8及以一下没有效果 。解决方法:
/** * 设置cookie * @param {String} key * @param {String} value * @param {Number} expires 单位为秒 * @param {String} path 路径 * @param {String} domain 主机 * @param {Boolean} secure 安全级别 */
function setCookie(key, value, expires, path, domain, secure) {
// key无效则不做任何操作
if (!key) {
return;
}
// 所有cookie的key都小写化处理
key = key.toLowerCase();
key = key + '=' + escape(value) + ";";
expires = expires ? ("expires=" + new Date(new Date().getTime() + expires * 1000).toGMTString()) + ";" : "";
path = !!path ? "path=" + path + ";" : "path=/;";
domain = domain ? ("domain=" + domain) + ";" : "";
secure = secure ? "secure=true;" : "";
document.cookie = [key, expires, path, domain, secure].join("");
}
//清除cookie
function clearCookie(name) {
var e = new Date();
e.setTime(e.getTime() - 1);
var b = getCookie(name);
document.cookie = name + "=" + name + ";path=/; domain=" + window.location.host + "; expires=" + e.toGMTString()
}
真实有效哦!!!!!
边栏推荐
猜你喜欢

Elastic APM installation and use

Innovus is stuck, prompting x error:

异常处理机制二

Selection and practice of distributed tracking system

volatile 靠的是MESI协议解决可见性问题?(上)

Under a directory of ext3 file system, subfolders cannot be created, but files can be created

面试题目大赏

Personality test system V1.0

2022 mobile crane driver test question simulation test question bank simulation test platform operation

搜索模块用例编写
随机推荐
nodejs服务后台执行(forever)
MySql5.7.25源码安装记录
暑假第四周
2022 Shanghai safety officer C certificate examination questions and mock examination
安卓 实现缓存机制,多种数据类型缓存
STM32+MFRC522完成IC卡号读取、密码修改、数据读写
arcgis的基本使用4
opencv 类的使用
PMM(Percona Monitoring and Management )安装记录
What is asynchronous operation
Does volatile rely on the MESI protocol to solve the visibility problem? (top)
[MySQL] understand the important architecture of MySQL (I)
【线上问题】Timeout waiting for connection from pool 问题排查
[Online deadlock analysis] by index_ Deadlock event caused by merge
使用openLayer画箭头
什么是异步操作
wap端微信h5支付,用于非微信浏览器
TabbarController的封装
Source code analysis of object wait notify notifyAll
2B and 2C