JQ如何设置Cookie
jquery.cookie.js 提供了jquery中非常简单的操作cookie的方法。
$.cookie('the_cookie')
; // 获得cookie$.cookie('the_cookie', 'the_value')
; // 设置cookie$.cookie('the_cookie', 'the_value', { expires: 7 })
; //设置带时间的cookie$.cookie('the_cookie', '', { expires: -1 })
; // 删除$.cookie('the_cookie', null)
; // 删除 cookie$.cookie('the_cookie', 'the_value', {expires: 7, path: '/', domain: 'jquery.com', secure: true})
;//新建一个cookie 包括有效期 路径 域名等
关于Iframe如何跨域访问Cookie和Session的解决方法
假如在网站A下通过iframe或ajax调用B下的内容时,默认情况下IE会阻止B写任何Cookie//B里的被调用的页面需要写P3P头,从而解除IE对写Cookie的阻止 context.Response.AddHeader("P3P", "CP=CAO PSA OUR"); //A里通过ajax调用
www.B.com
里的内容时,是跨域访问,需要使用jsonp,为配合其工作需要添加下面两句,生成jsonp返回 context.Response.ContentType = "text/plain"; context.Response.Write(string.Format("{0}('OK')", context.Request["callback"])); //jsonp调用进行跨域访问 jQuery.ajax({ url: url, type: 'GET', data: data, dataType: 'jsonp', success: function (data) { window.location.href = toURL; } });手机网站首页弹窗JS代码
// 注意引用jquery.js 和 jquery.cookie.js
$(function () {
var date = new Date().getDay();
if($.cookie("date") == undefined || $.cookie("date") == null){
// 说明当天没有打开这个弹窗,打开弹窗
alert("弹窗内容自己写,可以使用dialog");
$.cookie("date",date,7); //cookie 的有效时间 为 7 天
}else{
var cookieTime = $.cookie("date"); // 获取cookie保存的时间
if(cookieTime != date){
alert("弹窗内容自己写,可以使用dialog");
$(".alert-info").dialog("open");
}
}
});
还没有评论,来说两句吧...