js通过cookie对两个没有关系的jsp页面进行传值
//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 writeCookie (name, value, hours)
{
var expire = "";
if (hours != null)
{
expire = new Date ((new Date ()).getTime () + hours * 3600000);
expire = "; expires=" + expire.toGMTString ();
}
document.cookie = name + "=" + escape (value) + expire;
}
//调用设置
writeCookie ("myCookie", "my name", 24);
//调用取值
alert (readCookie ("myCookie"));
</script>
最新文章
- javascript仿天猫加入购物车动画效果
- git/github 使用
- hdu1251
- wpf 绑定ObservableCollection 的Count属性
- nodejs对静态文件目录的处理
- Spark RDD概念学习系列之Spark Hash Shuffle内幕彻底解密(二十)
- 新建PCH文件以及常用宏定义
- 自定义JsonResult处理JSON序列化DateTime类型数据(Ext4.2+ASP.NET MVC 4)
- vscode编写插件
- 转发:招聘一个靠谱的 iOS
- HDU 5616 Jam&#39;s balance
- 选择Web框架的20条标准
- 基础Gan代码解析
- VS开发入门一:VS常用快捷键大全,工欲善其事必先利其器 只看标红的吧
- 为什么用freemarker视图?
- win10 教育版本变专业版本
- linux中DHCP服务配置文件/etc/dhcpd.conf详细说明
- [Windows Azure] Managing SQL Database using SQL Server Management Studio
- Jenkins基础复习
- bzoj 1261 区间DP