浏览器设置cookie
2015-03-11 17:43 zhenjing 阅读(798) 评论(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/
未注明转载的文章,版权归作者所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
浙公网安备 33010602011771号