会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
。呢他
Powered by
博客园
博客园
|
首页
|
新随笔
|
|
|
管理
关于项目中的cookie操作
因为这个项目全都是基于的cookie,没有依靠Session,所以在客户端操作cookie尤为重要,下面我介绍2个封装好的方法操作cookie
读取cookie
function
readCookie(name)
{
var
cookieValue
=
""
;
var
search
=
name
+
"
=
"
;
if
(document.cookie.length
>
0
)
{
offset
=
document.cookie.indexOf(search);
if
(offset
!=
-
1
)
{
offset
+=
search.length;
end
=
document.cookie.indexOf(
"
;
"
, offset);
if
(end
==
-
1
) end
=
document.cookie.length;
cookieValue
=
unescape(document.cookie.substring(offset, end))
}
}
return
cookieValue;
}
更改或者添加cookie
function
setCookie(name, value)
{
var
today
=
new
Date()
var
expires
=
new
Date()
expires.setTime(today.getTime()
+
1000
*
60
*
60
*
24
*
365
)
document.cookie
=
name
+
"
=
"
+
escape(value)
+
"
; expires=
"
+
expires.toGMTString()
}
发表于
2006-11-16 09:31
在北京的湖南人
阅读(
519
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部