首先是html代码 一个checkbox 在其勾选上的时候设置一个Cookie的值!
<DIV align="center"><B><INPUT id="check1" type="checkbox" value="0" name="check"> <FONT color="#ff0000">下次不再提示此页面</FONT> <INPUT οnclick="subm();" type="button" value=" 确 定 " name="Submit"> </B></DIV>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>案事件一体化采集平台下载中心</title>
<link href="style/globe.css" rel="stylesheet" type="text/css">
<SCRIPT language="javascript">
//自动检验cookie的值!如果Cookie的值为quzongbo&&wangtianliang则自动跳转页面,
function autoJump()
{
var tmp =readCookie("cookieName");
if(tmp=="quzongbo&&wangtianliang")
{
document.location.href("http://100.100.100.218:8080//");
}
}
//读取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;
}
</SCRIPT>
</head>
<body onload = "autoJump();">
<SCRIPT language="javascript">
function subm()
{
if (document.getElementById("check").checked)
{
document.cookie ="cookieName=quzongbo&&wangtianliang";
}
document.location.href("http://100.100.100.218:8080//");
}
</SCRIPT>
</body>
此时的代码完成之后 无法再本地生成cookie !函数subm()作如下修改
function subm()
{
if (document.getElementById("check").checked)
{
addCookie("cookieName","quzongbo&&wangtianliang","99999999");
}
document.location.href("http://100.100.100.218:8080//");
}
function addCookie(objName,objValue,objHours){//添加cookie
var str = objName + "=" + escape(objValue);
if(objHours > 0){//为0时不设定过期时间,浏览器关闭时cookie自动消失
var date = new Date();
var ms = objHours*3600*1000;
date.setTime(date.getTime() + ms);
str += ";expires=" + date.toGMTString()+";path="+"/"+";";
}
document.cookie = str;
//alert("添加cookie成功");
}