zoukankan
html css js c++ java
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"
/>
查看全文
相关阅读:
自学Python3.5-字符串格式化 作用域 递归
自学Python3.2-函数分类(内置函数)
自学Python3.1-函数基础
自学Python2.7-collections系列
自学Python2.6-深浅拷贝
自学Python2.5-基本数据类型-set集合
自学Python2.4-基本数据类型-字典dict(objct)
自学Python2.3-基本数据类型-元组tuple(object) 方法
自学Python2.2-基本数据类型-列表list(object)
java通过jdbc访问mysql,update数据返回值的思考
原文地址:https://www.cnblogs.com/xiaobaigang/p/1189896.html
最新文章
自学Zabbix3.5-监控项item
自学Zabbix3.4-资产清单inventory
自学Zabbix3.3-一个简单例子 添加Hosts并应用模板
自学Zabbix3.2-配置功能简介
自学Zabbix3.1-语言切换
自学Zabbix2.6-zabbix升级
自学Zabbix2.5-客户端agentd安装过程
自学Zabbix2.4-web页面配置zabbix
自学Zabbix2.3-服务器端server安装过程
自学Zabbix2.2-服务器端环境配置
热门文章
自学Zabbix2.1-安装需求
自学Zabbix1.3-zabbix进程
自学Zabbix1.2-zabbix特性
自学Zabbix1.1-简介
自学Python6.4-内置模块(xml、conf、requests、logging、paramiko、time & datetime)
自学Python6.3-内置模块(os、sys、hashlib、random、json&pickle&shelve)
自学Python6.2-类、模块、包
自学Python6.1-模块简介
自学Python4.6-迭代器
自学Python4.1-文件操作
Copyright © 2011-2022 走看看