浏览器设置cookie
2015-03-11 17:43 zhenjing 阅读(791) 评论(0) 编辑 收藏 举报// Zepto.cookie plugin // // Copyright (c) 2010, 2012 // @author Klaus Hartl (stilbuero.de) // @author Daniel Lacy (daniellacy.com) // // Dual licensed under the MIT and GPL licenses: // http://www.opensource.org/licenses/mit-license.php // http://www.gnu.org/licenses/gpl.html ;(function($){ $.extend($, { cookie : function (key, value, options) { var days, time, result, decode; options = options || {}; if(!options.hasOwnProperty('path')){ options.path = '/'; } // A key and value were given. Set cookie. if (arguments.length > 1 && String(value) !== "[object Object]") { // Enforce object options = $.extend({}, options); if (value === null || value === undefined) options.expires = -1; if (typeof options.expires === 'number') { days = (options.expires * 1000); time = options.expires = new Date(); time.setTime(time.getTime() + days) } value = String(value); return (document.cookie = [ encodeURIComponent(key), '=', options.raw ? value : encodeURIComponent(value), options.expires ? '; expires=' + options.expires.toUTCString() : '', options.path ? '; path=' + options.path : '', options.domain ? '; domain=' + options.domain : '', options.secure ? '; secure' : '' ].join('')) } // Key and possibly options given, get cookie options = value || {}; decode = options.raw ? function (s) { return s } : decodeURIComponent; return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null } }) })(Zepto);
作者:zhenjing.chen
出处:http://www.cnblogs.com/zhenjing/
未注明转载的文章,版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步