码迷,mamicode.com
首页 > Web开发 > 详细

js通过cookie对两个没有关系的jsp页面进行传值

时间:2018-03-01 20:13:59      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:cap   gettime   value   exp   index   调用   new   offset   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>

js通过cookie对两个没有关系的jsp页面进行传值

标签:cap   gettime   value   exp   index   调用   new   offset   jsp   

原文地址:https://www.cnblogs.com/chenlove/p/8489646.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!