【Web Trick 8】JS操作cookie
来源:互联网 发布:linux修改eth0ip命令 编辑:程序博客网 时间:2024/06/01 09:40
最近要做的一个东西需要操作cookie,所以就把封装后的cookie发出来。
var Cookie = {add: function(objName, objValue, objHours) {var str = objName + "=" + escape(objValue);if (objHours > 0) {var date = new Date();var ms = objHours * 3600 * 1000;date.setTime(date.getTime() + ms);str += "; expires=" + date.toGMTString();}document.cookie = str;},get: function(objName) {var arrStr = document.cookie.split("; ");var return_temp=false;for (var i = 0; i < arrStr.length; i++) {var temp = arrStr[i].split("=");if (temp[0] == objName) {return_temp=true;return unescape(temp[1]);}}if (!return_temp) {return null;}},del: function(name) {var date = new Date();date.setTime(date.getTime() - 10000);document.cookie = name + "=a; expires=" + date.toGMTString();}}
如果需要设置session级别的cookie的话,可以将add改成如下代码
function(objName, objValue){ var isIE= $.browser.msie;//判断是否是ie核心浏览器 if(isIE){ if(value){ var expire = "; expires=At the end of the Session"; document.cookie = objName+ "=" + escape(objValue) + expire; } }else{ if(value){ var expire = "; expires=Session"; document.cookie = objName + "=" + escape(objValue) + expire; } } }
- 【Web Trick 8】JS操作cookie
- 【Web Trick 3】常用的js字符串操作函数
- cookie.js js操作cookie
- jquery.cookie.js操作cookie-
- jquery.cookie.js操作Cookie
- jquery.cookie.js操作Cookie
- Web中cookie操作
- web页面操作cookie
- JS脚本操作COOKIE
- JS 对 cookie 操作
- js cookie 的操作
- JS操作Cookie详解
- JS操作Cookie详解
- js 操作cookie详解
- JS进行Cookie操作
- JS操作COOKIE
- js cookie 的操作
- js操作cookie
- iOS 5 ARC 入门 (1/3)
- ubuntu grep 用法
- base.css
- C语言开发工具Win-TC
- Js 的 apply()、call()
- 【Web Trick 8】JS操作cookie
- 关于比较符合语义的新闻列表
- android开发中的代码优化建议
- Unable to resolve target 'android-10' 问题的解决
- uCOS2_CPU利用率的实现
- 自由变量记录
- iOS 5 ARC 入门 (2/3)
- 关于资源站项目小结
- 研究生是否应该读博?