javaScript Cookie操作以及页面弹出层实现

cookie的操作

//CuPlayer.com提示说明:参数说明: 
//CKname是cookie名称(必填), 
//CKvalue是cookie值(必填), 
//duration是过期时间(默认为关闭浏览器), 
//CKpath是可访问cookie的目录(默认为所有页面), 
//CKdomain是可访问cookie的主机名(默认为当前域名下[子域名]); 
function setCookie(CKname,CKvalue,duration,CKpath,CKdomain) 
{ 
var NewDate = new Date(); 
NewDate.setTime(NewDate.getTime()+duration*24*60*60*1000); 
document.cookie = CKname+"="+escape(CKvalue)+(duration?";expires="+NewDate.toGMTString():"")+(CKpath?";path="+CKpath:"")+(CKdomain?";domain="+CKdomain:""); 
}; 
JScript 代码
//参数: 
//CKname:Cooke名称 
function getcookie(CKname) 
{ 
var arrCookie = document.cookie.match(new RegExp("(^| )"+CKname+"=([^;]*)(;|$)")); 
if(arrCookie!=null) 
{ 
return unescape(arrCookie[2]); 
} 
else 
{ 
return null; 
}; 
}; 

JScript 代码
//删除指定名称的cookie 
function deleteCookie(CKname) 
{ 
document.cookie = CKname+"=;expires="+(new Date(0)).toGMTString(); 
}; 

java修改cookie

/**
* 设置cookie
* @param response
* @param name cookie名字
* @param value cookie值
* @param maxAge cookie生命周期 以秒为单位
*/
public static void addCookie(HttpServletResponse response,String name,String value,int maxAge){
Cookie cookie = new Cookie(name,value);
cookie.setPath("/");
if(maxAge>0) cookie.setMaxAge(maxAge);
response.addCookie(cookie);
}

get新技能

直接放在javascripts,能实现界面的弹出层。

layer.open({
type: 2,
title: false,
closeBtn: 0, //不显示关闭按钮
shade: [0],
area: ['340px', '215px'],
offset: 'rb', //右下角弹出
time: 2000, //2秒后自动关闭
anim: 2,
content: ['test/guodu.html', 'no'], //iframe的url,no代表不显示滚动条
end: function(){ //此处用于演示
layer.open({
type: 2,
title: '很多时候,我们想最大化看,比如像这个页面。',
shadeClose: true,
shade: false,
maxmin: true, //开启最大化最小化按钮
area: ['893px', '600px'],
content: 'http://fly.layui.com/'
});
}
});

 

posted @ 2018-01-29 18:15  用什么暖你一千岁!  阅读(1309)  评论(0编辑  收藏  举报