JavaScript 下次不再提示此页面

首先是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成功");
}

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值