当前位置:网站首页>解决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()
}
真实有效哦!!!!!
边栏推荐
猜你喜欢
随机推荐
调用DLL开启线程的问题
OnTap 9 file system limitations
性格测试系统v1.0
opencv图像处理
Selection and practice of distributed tracking system
Sliding window, double pointer, monotone queue, monotone stack
838. Heap sorting
JVM command induction
大二上第一周学习笔记
C# 托管与非托管
Android implements the caching mechanism and caches multiple data types
Object 的Wait Notify NotifyAll 源码解析
Mysql事务
What is asynchronous operation
Windows backs up the database locally by command
js中树与数组的相互转化(树的子节点若为空隐藏children字段)
滑动窗口、双指针、单调队列、单调栈
asp.net 使用redis缓存(二)
a-table中的rowSelection清空问题
Your login IP is not within the login mask configured by the administrator









