网上有个jquery cookie的插件,代码贴一下
jQuery.cookie = function (name, value, options) {
if (typeof value != 'undefined') {
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();
}
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 {
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]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
}; 我现在想请教下就是如何设置cookie跨域使用
比如我在localhost:20000/a.htm中设置cookie
$.cookie('mycookie','mucookievalue',{?????})
想在localhost:200001/b.htm中获取mycookie的内容{?????}这里怎么写
jQuery.cookie = function (name, value, options) {
if (typeof value != 'undefined') {
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();
}
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 {
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]);
if (cookie.substring(0, name.length + 1) == (name + '=')) {
cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
break;
}
}
}
return cookieValue;
}
}; 我现在想请教下就是如何设置cookie跨域使用
比如我在localhost:20000/a.htm中设置cookie
$.cookie('mycookie','mucookievalue',{?????})
想在localhost:200001/b.htm中获取mycookie的内容{?????}这里怎么写
解决方案 »
- CKEditor功能扩展示例--为image对话框添加自己的upload按钮
- 求解如何在 JavaScript 中解析字符串
- Javascript菜鸟问题
- 弹出窗口如何才能显示后退按钮那一排的按钮
- ext中的TabPanel的选项卡能不能销毁
- tree前加checkbox,数据写在JS中,如何判断选中并存入FORM中呢?表单如何取值?
- 这是什么面试测试题?夸张了一些!!
- 动态建立一个div,想指定相对位置,应该怎么做?
- 表格中行的内容太大,把表格涨大了,如何得到涨大后的真实大小?
- ios下click事件要点击两次才有响应
- (100分悬赏)跪求jsp页面控件内文字方向设置问题解决方案
- 用Ajax调用WebMethod方法,不执行
$.cookie('mycookie')