首页 > 代码库 > cookie操作简单实现
cookie操作简单实现
var Cookie = { get:function(key){ var reg = new RegExp(‘^‘ + key + ‘=([^;]+)(?=;|$)‘,‘gi‘); return (result = document.cookie.match(reg)) == null ? null : decodeURICompoent(result[1]); }, set:function(key,value,expireHours,path,domain,secure){ var path = path || ‘/‘, domain = domain || location.host, cookie = [key + ‘=‘ + encodeURICompoent(value),‘path=‘ + path,‘domain=‘+domain]; if(expire){ cookie.push(‘expires=‘ + this.hoursToExpire(expireHours)) } if(secure){ cookie.push(secure) } document.cookie = cookie.join(‘‘); return document.cookie; }, del:function(key){ if(this.get(key)){var expire = new Date(); expire.setTime(now.getTime() - 10000); this.set(key,‘‘,expire,path,domain); } }, hoursToExpire:function(hours){ if(parseInt(hours) == NaN){ return ‘‘; } var now = new Date(); now.setTime(now.getTime() + parseInt(hours)*60*60*1000); return now.toGMTString(); } }
cookie操作简单实现
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。