我已经离开web开发一段时间了,所以非常生锈。 我需要做出一个Cookie设置js简单的cookie
- 如果用户访问该网站>设置cookie的
- 如果用户回来到网站>读取Cookie
- 如果时间自用户最后到达小于24小时>设置div的ID为style =“display:none;”
即时通讯挣扎,真的很感激一些指导。
感谢这么多
我已经离开web开发一段时间了,所以非常生锈。 我需要做出一个Cookie设置js简单的cookie
即时通讯挣扎,真的很感激一些指导。
感谢这么多
使用JavaScript可以
- 读取Cookie:
var coo = [],
a;
if(document.cookie != ''){
$.each(document.cookie.split('; '), function(i, val){
a = val.split('=');
coo[a[0]] = a[1];
});
}
在这里,我们有所有的cookies(coo['Cookie1'] == 'value'
)一coo
。
- 集饼干:
document.cookie = 'Cookie_1='+'value for this cookie';
BTW代码使用jQuery的$。每。
下面有杂乱的溶液I凸轮了的情况下,任何人想知道:
function nameDefined(ckie,nme)
{ 变种splitValues 变种我 为(I = 0;我 tvalue = getCookieValue(nvpair,CNAME) //获取饼干 的值,如果(tvalue == cvalue)返回true 否则返回false } 否则返回false } 功能redirectLink(){ 如果(testCookie( “here10”, “是”)) { //window.location="here.html“//转到指示用户已在这里的位置 // alert(”there“); window.document.getElementById(“indicator”)。style.display =“none”; } else { // alert(“not there”); var futdate = new Date()//获取当前时间和日期 var expdate = futdate.getTime()//获取自1970年1月1日以来的毫秒数 expdate + = 10000 //在1小时后过期(毫秒) futdate.setTime(expdate) var newCookie =“here10 = yes; path = /;” //设置新的cookie值 newCookie + =“expires =”+ futdate.toGMTString() window.document.cookie = newCookie //写入Cookie // window.location =“not.html”// Go指示用户的位置已经没有在这里
window.document.getElementById("indicator").style.display = "block";
}}
什么语言,你在寻找实现这一点?服务器端,还是JavaScript? – JAL 2010-01-28 02:52:13
javascript谢谢代码鸭... 只是想保持它真正简单 – chris 2010-01-28 04:30:47