一款js 读取cookie 值代码

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.w3.org/tr/xhtml1/dtd/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=gb2312" />
<title>一款js 读取cookie 值代码</title>
<script>
function getcookie(sname)
{
  // cookies are separated by semicolons
  var acookie = document.cookie.split("; ");
  for (var i=0; i < acookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var acrumb = acookie[i].split("=");
    if (sname == acrumb[0])
      return decodeuricomponent(acrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

//读取cookie方法
getcookie('www.111cn.net');

</script>
</head>

<body>
</body>
</html>

时间: 2024-12-25 13:29:04

一款js 读取cookie 值代码的相关文章

js设置与读取cookie值代码

js设置与读取cookie值代码 <script language="javascript教程">  function setCookie(name, value)  //cookies设置 {  var argv = setCookie.arguments;  var argc = setCookie.arguments.length;  var expires = (argc > 2) ? argv[2] : null;  if(expires!=null)  {

js 删除所有cookie值代码

cookie 是存储于访问者的计算机中的变量.每当同一台计算机通过浏览器请求某个页面时,就会发送这个 cookie.你可以使用 javascript 来创建和取回 cookie 的值. 下面来看款删除所有cookie值代码 function clearcookie(){ var keys=document.cookie.match(/[^ =;]+(?==)/g); if (keys) { for (var i = keys.length; i--;) document.cookie=keys[

js /jquery 获取cookie值代码

js /jquery 获取cookie值代码 */ function getcookie(name, dc){       var cname = name + "=";     if (dc.length > 0){           var begin = dc.indexof(cname);         if (begin != -1){               begin += cname.length;               end = dc.index

js 读取数据值

js 读取数据值 var params = new Enumerator(Request.QueryString); while (!params.atEnd()) { Response.Write(params.item() + ":" + Request.QueryString(params.item()) + "<br />"); params.moveNext(); } 美中不足的是,Request对象本身不是集合,所以不能对Request对象进

二款js 年月日星期显示代码

二款js 年月日星期显示代码  <SCRIPT language=javascript教程> function showDate() { var d = new Date();  document.write("<div class="date_div">"+d.getYear()+"年"+(d.getMonth()+1)+"月"+d.getDate()+"日"); switch(d

读取cookie值

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title>读取cookie值 www.111cn.net  New Document </title> <meta name="Generator" content="EditPlus"> <meta name=&

js 读取cookie 清除cookie

<!doctype html public "-//w3c//dtd xhtml 1.0 transitional//en" "http://www.111cn.net/tr/xhtml1/dtd/xhtml1-transitional.dtd"> <html xmlns="http://www.111cn.net/1999/xhtml"> <head> <meta http-equiv="co

js设置cookie,获取cookie值及删除cookie值代码

function SetCookie (name, value) {        var exp = new Date();        exp.setTime (exp.getTime()+3600000000);        document.cookie = name + "=" + value + "; expires=" + exp.toGMTString()+"; path=/"; } function getCookieVal

js取得cookie值的函数

由于asp的cookie是经过url编码的,所以读之前要unescape一下. 下面是我用正则的方法取cookie,包括单值和多值: /**************************************************  参数说明:  sMainName Cookie名  sSubName Cookie子键名,留空表示单值Cookie  **************************************************/  function GetCookie