jQuery.cookie.js文件内容相信看到这的朋友都有了:
jQuery.cookie = function(name, value, options) {
if (typeof value != 'undefined') { // name and value given, set cookie
options = options || {};
if (value === null) {
value = '';
options.expires = -1;
}
var expires = '';
if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
var date;
if (typeof options.expires == 'number') {
date = new Date();
date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
} else {
date = options.expires;
}
expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
}
var path = options.path ? '; path=' + options.path : '';
var domain = options.domain ? '; domain=' + options.domain : '';
var secure = options.secure ? '; secure' : '';
document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
} else { // only name given, get cookie
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
for (var i = 0; i < cookies.length; i++) {
var cookie = jQuery.trim(cookies[i]);
// Does this cookie string begin with the name we want?
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
}
向cookie中设置一个值后,另一个页面取不到cookie的值:
http://test.com/a/index.html中$.cookie('cookiename', 'test_val', {expires: 7, path: '/', domain: 'test.com', secure: true});
在http://test.com/b/index.html中$.cookie('cookiename')返回为空,而http://test.com/a/test.html中确返回 test_val,弄半天,domain设置没错,path也正确,,,,翻看各种api和各种搜索,,,还是找不到答案,我去!!!!!!!!
折腾N久,,,一步步测试,,,将secure设置成false后,,,能读取到,真是发现新大陆一样。。。。我擦!!!!
rocord下来。。。。。。。。