⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cookie.htm

📁 有很多很实用的方法
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb_2312-80">
<meta name="GENERATOR" content="Microsoft FrontPage 3.0">
<title>javascript</title>
</head>

<body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#660099">

<table border="0" cellpadding="0" width="530" celspacing="0">
  <tr>
    <td colspan="2" width="528"><font size="3" color="#0000FF" face="宋体"><a
    href="../../../tppmsgs/msgs0.htm#52" tppabs="http://www.webmonkey.com.cn/design.html" target="_top">网页设计</a><a
    href="../../../tppmsgs/msgs0.htm#53" tppabs="http://www.webmonkey.com.cn/html.html" target="_top">/HTML文件</a><a
    href="../../../tppmsgs/msgs0.htm#32" tppabs="http://www.webmonkey.com.cn/dynamic_html.htm" target="_top">/动态HTML文件</a></font><a
    href="../../../tppmsgs/msgs0.htm#54" tppabs="http://www.webmonkey.com.cn/stylesheets.html"><font size="2" color="#0000FF"
    face="宋体">/Stylesheets</font></a><font size="3" color="#0000FF" face="宋体"><a
    href="../../../tppmsgs/msgs0.htm#55" tppabs="http://www.webmonkey.com.cn/graphics.html" target="_top">/图形与字体</a><a
    href="../../../tppmsgs/msgs0.htm#56" tppabs="http://www.webmonkey.com.cn/multimedia.html" target="_top">/多媒体</a></font><font
    size="2" color="#0000FF" face="宋体">&nbsp;</font></td>
  </tr>
  <tr>
    <td colspan="2" width="528"><a href="../../../tppmsgs/msgs0.htm#57" tppabs="http://www.webmonkey.com.cn/browsers.html"
    target="_top"><font size="3" color="#0000FF" face="宋体">浏览器</font></a><font
    size="2" color="#0000FF" face="宋体"><a href="../../../tppmsgs/msgs0.htm#58" tppabs="http://www.webmonkey.com.cn/java.html">/Java</a><a
    href="../../../tppmsgs/msgs0.htm#31" tppabs="http://www.webmonkey.com.cn/javascript.html">/JavaScript</a><a
    href="../../../tppmsgs/msgs0.htm#33" tppabs="http://www.webmonkey.com.cn/perl.html">/<nobr>Perl</nobr></font><font
    color="#0000FF" face="宋体">语言</font></a><nobr><font size="2" color="#0000FF"
    face="宋体"><a href="../../../tppmsgs/msgs0.htm#59" tppabs="http://www.webmonkey.com.cn/backend.html">/Backend</a><a
    href="../../../tppmsgs/msgs0.htm#60" tppabs="http://www.webmonkey.com.cn/e_business.htm">/</font><font size="3" color="#0000FF"
    face="宋体">电子商务</font></a></nobr></td>
  </tr>
  <tr>
    <td width="528" colspan="2"><br>
    <font face="宋体"><nobr><!-- TOP NAVIGATION and SPONSOR STUFF --> <font size="5"><a href="../../../tppmsgs/msgs0.htm#50" tppabs="http://www.webmonkey.com.cn/javascript/code/webmonkey.html"><b>webmonkey</b></a><a
    href="../../../tppmsgs/msgs0.htm#31" tppabs="http://www.webmonkey.com.cn/javascript.html">/javascript</a><a href="code.htm" tppabs="http://www.webmonkey.com.cn/javascript/code/code.htm">/code</a>/ 
    form_data</font></nobr></font></td>
  </tr>
  <tr>
    <td width="219"></td>
    <td width="307"><p align="left"><big><big><strong><font color="#FF0000">网猴Cookie集锦</font></strong></big></big><br>
    作者:<font color="#0000FF"><font size="2" face="arial, helvetica, sans-serif"><a
    href="mailto:nadav@hotwired.com" title="Send
mail to Nadav Savio">Nadav Savio</a></font> </font></td>
  </tr>
</table>

<table border="0" cellpadding="0" width="540" celspacing="0">
<!-- sponsor -->
<!-- BUFFER -->
  <tr>
    <td rowspan="99" width="15"></td>
    <td valign="top" rowspan="99" width="195" bgcolor="#FFFFB5"><font face="宋体"><img
    src="../../../static.wired.com/webmonkey/images/spacer.gif" tppabs="http://static.wired.com/webmonkey/images/spacer.gif" width="195" height="1"><br>
    </font><font size="2"><a href="wm_ckie_bh.html" tppabs="http://www.webmonkey.com.cn/javascript/code/wm_ckie_bh.html"><b>网猴的<font face="宋体">Cookie</font>行为</b></a></font><font
    face="宋体"><br>
    </font><font size="2">这<font face="宋体">3</font>种行为很容易在<font
    face="宋体">Dreamweaver<br>
    </font>编辑器中设置、读取和删除。</font><p><a
    href="../../../tppmsgs/msgs0.htm#74" tppabs="http://www.webmonkey.com.cn/e_business/cookies1.htm"><b><font size="2">重新考察</font><font
    face="宋体" size="2">Cookies</font></b></a><font face="宋体"><br>
    </font><font face="宋体" size="2">Marc</font><font size="2">讨论对<font face="宋体">cookie</font>的滥用,并解释如何纠正。</font></p>
    <p><a href="../../../tppmsgs/msgs0.htm#75" tppabs="http://www.webmonkey.com.cn/e_business/cookie_dowhat.htm"><font size="2"><b><font
    face="宋体">Cookies</font>能为你做什么?</b></font></a><font face="宋体"><br>
    </font><font face="宋体" size="2">Len</font><font size="2">从网络设计者的角度探讨<font
    face="宋体">cookies</font>的用途。</font><font face="宋体"> </font></p>
    <p><font face="宋体"><!-- RESOURCES --><!-- <font size="4" face="arial, helvetica, sans-serif"><B>Resources</B></font><br> --><!-- COLLECTION RESOURCES --><font size="2"><b>CGI Programming on the World</b></font><br>
    </font><font size="2"><i>对</i><font face="宋体">CGI</font>及相关技术的研究,包括对<font
    face="宋体">CGI</font>编程细节的解释。</font><font face="宋体" size="2"> <a
    href="../../../tppmsgs/msgs0.htm#63" tppabs="http://shop.barnesandnoble.com/booksearch/isbnInquiry.asp?isbn=1565921682"><i><nobr>Learn 
    more...</nobr></i></a></font><font face="宋体"> <br>
    <br>
    </font><a href="layout_css.html" tppabs="http://www.webmonkey.com.cn/javascript/code/layout_css.html"><font size="2"><b>网猴的<font face="宋体">netscapeCSS</font>浏览器窗口尺寸改变时的纠正器</b></font></a><font
    face="宋体"><br>
    </font><font size="2">这几种函数可以纠正不幸的<br>
    <font face="宋体">Netscape 4</font>在显示带有<font face="宋体">CSS</font>属性<br>
    的网页时如果改变了浏览器窗口<br>
    的尺寸而带来的<font face="宋体">CSS</font>信息缺损。<br>
    </font><br>
    <font face="宋体"><small><a
    href="../tutor/tutorial1_page1.html" tppabs="http://www.webmonkey.com.cn/javascript/tutor/tutorial1_page1.html"><b><font
    face="宋体">JavaScript</font>教程<font face="宋体">: </font>第一天</b></a><br>
    </small><font size="1">Thau </font><small>向你介绍<font face="宋体">JavaScript ,</font>同</small><br>
    <small>时带你开始写你的第一个程序<font face="宋体">.</font></small></font></p>
    <p><font face="宋体"><!-- Book Reviews --> <br>
    </font></td>
<!-- BUFFER -->
    <td rowspan="99" width="10"></td>
    <td valign="top" width="320"><font size="2"> <table width="357" border="0" cellpadding="0"
    cellspacing="0">
      <font face="verdana, arial, geneva, sans-serif" size="2">
      <tr>
        <td></font></font><font size="3">这些函数能简化使用<font face="宋体">cookies</font>时的麻烦。它包括<br>
        各种设置、读取和删除<font face="宋体">cookies</font>的各种函数,以<br>
        及一个测试用户是否接受<font face="宋体">cookies</font>查询的函数。 <p><b>用途:</b><br>
        <font face="宋体"><tt>WM_setCookie('name', 'value'[, hours, <br>
        'path', 'domain', secure]);</tt> <br>
        </font>在这里<font face="宋体"><tt>name</tt></font>、<font face="宋体"><tt>value</tt></font>和<font
        face="宋体"><tt>path</tt></font>都是字符串,<font face="宋体"><tt>secure</tt></font><br>
        是<font face="宋体">true</font>或者<font face="宋体">null</font>。只有<font
        face="宋体"><tt>name</tt></font>和<font face="宋体"><tt>value</tt></font>是必须项。 
        </p>
        <p><font face="宋体"><tt>WM_readCookie('name');</tt> <br>
        </font>返回和<font face="宋体"><tt>name</tt></font>有关的参数值。<font
        face="宋体">. </font></p>
        <p><font face="宋体"><tt>WM_getCookieValue('name');</tt> <br>
        </font>这个函数是<font face="宋体"><nobr>WM_readCookie()</nobr></font>和<font
        face="宋体"><nobr>WM_killCookie()</nobr> </font><br>
        函数的辅助函数。它根据<font face="宋体"><tt>name</tt></font>提取一个参数值,<br>
        条件是<font face="宋体">cookie</font>采取<font face="宋体">'name=value'</font>的格式。</p>
        <p><font face="宋体"><tt>WM_killCookie('name'[, 'path', 'domain']);</tt> <br>
        </font>注意如果在<font face="宋体">cokie</font>中设置了<font face="宋体">path</font>和<font
        face="宋体">domain</font>,则此<br>
        处必须提供<font face="宋体"><tt>path</tt></font>和<font face="宋体"><tt>domain</tt></font>参数。 
        </p>
        <p><font face="宋体"><tt><nobr>WM_acceptsCookies()</nobr>;</tt> <br>
        </font>返回<font face="宋体"><tt>true</tt></font>或<font face="宋体"><tt>false</tt></font>。 
        </font></td>
      </tr>
    </table>
    <p><b>欢迎剪贴和使用这些函数<font face="宋体">!</b> </font><font size="2"></p>
    <form>
      <p><font face="宋体"><textarea cols="45" rows="20" wrap="off">

&lt;script language=&quot;JavaScript&quot;&gt;
<!--



/*
WM_setCookie(), WM_readCookie(), WM_killCookie(), WM_acceptsCookies()
A set of functions that eases the pain of using cookies.

Source: Webmonkey Code Library
(http://www.hotwired.com/webmonkey/javascript/code_library/)

Author: Nadav Savio
Author Email: nadav@wired.com

Usage: 

WM_setCookie('name', 'value'[, hours, 'path', 'domain', secure]);
where name, value, and path are strings, and secure is either true or null. Only name and value are required.

WM_readCookie('name');
Returns the value associated with name.

WM_getCookieValue('name');
This is a helper function used by WM_readCookie() and WM_killCookie(). It extracts a single value based on name, given a cookie of the form 'name=value'.

WM_killCookie('name'[, 'path', 'domain']);
Remember that path and domain must be supplied if they were set with the cookie.

WM_acceptsCookies();
Returns true or false.
*/

function WM_acceptsCookies() {
  // This function tests whether the user accepts cookies.
  // Declare variable.
  var answer;
  // Try to set a cookie.
  document.cookie = 'WM_acceptsCookies=yes';
  // If it fails, return false; if it succeeds, return true.
  if(document.cookie == '') answer = false; else answer = true;
  // Then clean up by expiring the cookie.
  document.cookie = 'WM_acceptsCookies=yes; expires=Fri, 13-Apr-1970 00:00:00 GMT';
  return answer;
}

function WM_setCookie (name, value, hours, path, domain, secure) {
  // Don't waste your time if the browser doesn't accept cookies.
  if (WM_acceptsCookies()) {
    // Set the cookie, adding any parameters that were specified.
    // (Convert hours to milliseconds (*3600000) 
    // and then to a GMTString.)
    document.cookie = name + '=' + escape(value) + ((hours)?(';expires=' + ((new Date((new Date()).getTime() + hours*3600000)).toGMTString())):'') + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'') + ((secure && (secure == true))?'; secure':'');
  }
}

function WM_readCookie(name) {
  // if there's no cookie, return false else get the value and return it
  if(document.cookie == '') return false; 
  else return unescape(WM_getCookieValue(name));
}

function WM_getCookieValue(name) {
  // Declare variables.
  var firstChar, lastChar;
  // Get the entire cookie string. (This may have other name=value pairs in it.)
  var theBigCookie = document.cookie;
  // Grab just this cookie from theBigCookie string.
  // Find the start of 'name'.
  firstChar = theBigCookie.indexOf(name);
  // If you found it,
  if(firstChar != -1) {
    // skip 'name' and '='.
    firstChar += name.length + 1;
    // Find the end of the value string (i.e. the next ';').
    lastChar = theBigCookie.indexOf(';', firstChar);
    if(lastChar == -1) lastChar = theBigCookie.length;
    // Return the value.
    return theBigCookie.substring(firstChar, lastChar);
  } else {
    // If there was no cookie, return false.
    return false;
  }
}

function WM_killCookie(name, path, domain) {
  // We'll need the name and the value to kill the cookie, so get the value.
  var theValue = WM_getCookieValue(name);
  // Assuming there actually is such a cookie.
  if(theValue) {
    // Set an expired cookie, adding 'path' and 'domain' 
    // if they were given.
    document.cookie = name + '=' + theValue + '; expires=Fri, 13-Apr-1970 00:00:00 GMT' + ((path)?';path=' + path:'') + ((domain)?';domain=' + domain:'');
  }
}


// -->

&lt;/script&gt;

</textarea> </font></p>
    </form>
    <p><font face="宋体"><br>
<!-- AUTHOR TAGLINE -->    </font></font></td>
  </tr>
</table>

<p><font face="宋体"><br>
</font></p>
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -