runxinzhi.com
首页
百度搜索
cookies 客户端历史记录篇
Web客户端经常要跟踪用户访问的历史页面,如当当网当中的最近浏览的书籍, 这样的数据一般保存在客户端的cookies中
具体实现代码
<
script
language
=javascript
>
function
getCookie(c_name)
{
var
item
=
""
;
if
(document.cookie.length
>
0
)
{
c_start
=
document.cookie.indexOf(c_name
+
"
=
"
);
if
(c_start
!=-
1
)
{
c_start
=
c_start
+
c_name.length
+
1
;
c_end
=
document.cookie.indexOf(
"
;
"
,c_start);
if
(c_end
==-
1
) c_end
=
document.cookie.length;
item
=
unescape(document.cookie.substring(c_start,c_end));
}
}
return
item;
}
function
setCookie(c_name,value,expiredays)
{
var
item
=
getCookie(c_name);
//
先取以前的,再追加现在的value
if
(item.indexOf(value)
<
0
)
//
如果追加的值已经存在
{
var
exdate
=
new
Date();exdate.setDate(exdate.getDate()
+
expiredays);
document.cookie
=
c_name
+
"
=
"
+
escape(value
+
"
**
"
+
item)
+
((expiredays
==
null
)
?
""
:
"
;expires=
"
+
exdate.toGMTString());
}
else
{
alert(
'
Value Already Exists
'
);
}
}
</
script
>
Js调用
<
input
id
="Submit"
type
="submit"
onclick
="setCookie('producthistory','bookid|bookname',1)"
value
="submit"
/>
相关阅读:
generator
JS 中 apply 、call 、bind的详解
前端面试题(24-js)
JS原型链深入了解
Java12新特性
Java11-ZGC
Java11新特性
Java10新特性
Java9新特性
CF1385E【Directing Edges】 (拓扑排序)
原文地址:https://www.cnblogs.com/xiaobaigang/p/1189896.html
最新文章
ps命令
pmap内存分析工具
hcache查看系统缓存
tomcat配置错误页面
Tomcat部署web应用的方式
tomcat的单机多实例启动
weblogic 12c安装
WinDBG 搜索指令结果
LLVM + libFuzzer ,编译命令生成脚本
本人回应华为禁止我因学历问题入职其公司:不公平、不可接受,望重新评估
热门文章
【djangoframework序列化】序列化添加自定义内容 例子:二级回复评论
laravel maatwebsite/excel 导出Excel
Default value for parameters with a class type hint can only be NULL
修复Laravel The only supported ciphers are AES-128-CBC and AES-256-CBC 问题
常见前端面试题03
常见前端面试题02
红宝书4-第八章对象、类与面向对象编程(1)
常见前端面试题01
14计优化网站
前端面试题(25-js)
Copyright © 2020-2023
润新知