/* Cookie Library -- "Night of the Living Cookie" Version (25-Jul-96)
2缔友计算机信息技术有限公司,涂聚文 geovindu@163.com 互相交流
3 Written by: Bill Dortch, hIdaho Design <geovindu@163.com>
4 The following functions are released to the public domain.
5http://www.dusystem.com/
6 This version takes a more aggressive approach to deleting
7 cookies. Previous versions set the expiration date to one
8 millisecond prior to the current time; however, this method
9 did not work in Netscape 2.02 (though it does in earlier and
later versions), resulting in "zombie" cookies that would not
die. DeleteCookie now sets the expiration date to the earliest
usable date (one second into 1970), and sets the cookie's value
to null for good measure.
Also, this version adds optional path and domain parameters to
the DeleteCookie function. If you specify a path and/or domain
when creating (setting) a cookie**, you must specify the same
path/domain when deleting it, or deletion will not occur.
The FixCookieDate function must now be called explicitly to
correct for the 2.x Mac date bug. This function should be
called *once* after a Date object is created and before it
is passed (as an expiration date) to SetCookie. Because the
Mac date bug affects all dates, not just those passed to
SetCookie, you might want to make it a habit to call
FixCookieDate any time you create a new Date object:
var theDate = new Date();
FixCookieDate (theDate);
Calling FixCookieDate has no effect on platforms other than
the Mac, so there is no need to determine the user's platform
prior to calling it.
This version also incorporates several minor coding improvements.
**Note that it is possible to set multiple cookies with the same
name but different (nested) paths. For example:
SetCookie ("color","red",null,"/outer");
SetCookie ("color","blue",null,"/outer/inner");
However, GetCookie cannot distinguish between these and will return
the first cookie that matches a given name. It is therefore
recommended that you *not* use the same name for cookies with
different paths. (Bear in mind that there is *always* a path
associated with a cookie; if you don't explicitly specify one,
the path of the setting document is used.)
Revision History:
"Toss Your Cookies" Version (22-Mar-96)
- Added FixCookieDate() function to correct for Mac date bug
"Second Helping" Version (21-Jan-96)
- Added path, domain and secure parameters to SetCookie
- Replaced home-rolled encode/decode functions with Netscape's
new (then) escape and unescape functions
"Free Cookies" Version (December 95)
For information on the significance of cookie parameters, and
and on cookies in general, please refer to the official cookie
spec, at:
http:www.netscape.com/newsref/std/cookie_spec.html
****************************************************************** */
/**//* "Internal" function to return the decoded value of a cookie */
复制代码 代码如下:
function getCookieVal (offset) {
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1) {
endstr = document.cookie.length;
}
return unescape(document.cookie.substring(offset, endstr));
}
/**//* Function to correct for 2.x Mac date bug. Call this function to
fix a date object prior to passing it to SetCookie.
IMPORTANT: This function should only be called *once* for
any given date object! See example at the end of this document. */
复制代码 代码如下:
function FixCookieDate (date) {
var base = new Date(0);
var skew = base.getTime(); // dawn of (Unix) time - should be 0
if (skew > 0) { // except on the Mac - ahead of its time
date.setTime(date.getTime() - skew);
}
}
/**//* Function to return the value of the cookie specified by "name".
name - String object containing the cookie name.
returns - String object containing the cookie value, or null if
the cookie does not exist. */
复制代码 代码如下:
function GetCookie (name) {
var temp = name + "=";
var tempLen = temp.length;
var cookieLen = document.cookie.length;
var i = 0;
while (i < cookieLen) {
var j = i + tempLen;
if (document.cookie.substring(i, j) == temp) {
return getCookieVal(j);
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
/**//* Function to create or update a cookie.
name - String object containing the cookie name.
value - String object containing the cookie value. May contain
any valid string characters.
[expiresDate] - Date object containing the expiration data of the cookie. If
omitted or null, expires the cookie at the end of the current session.
[path] - String object indicating the path for which the cookie is valid.
If omitted or null, uses the path of the calling document.
[domain] - String object indicating the domain for which the cookie is
valid. If omitted or null, uses the domain of the calling document.
[secure] - Boolean (true/false) value indicating whether cookie transmission
requires a secure channel (HTTPS).
The first two parameters are required. The others, if supplied, must
be passed in the order listed above. To omit an unused optional field,
use null as a place holder. For example, to call SetCookie using name,
value and path, you would code:
SetCookie ("myCookieName", "myCookieValue", null, "/");
Note that trailing omitted parameters do not require a placeholder.
To set a secure cookie for path "/myPath", that expires after the
current session, you might code:
SetCookie (myCookieVar, cookieValueVar, null, "/myPath", null, true); */
复制代码 代码如下:
function SetCookie (name,value,expiresDate,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expiresDate) ? "; expires=" + expiresDate.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
/**//* Function to delete a cookie. (Sets expiration date to start of epoch)
name - String object containing the cookie name
path - String object containing the path of the cookie to delete. This MUST
be the same as the path used to create the cookie, or null/omitted if
no path was specified when creating the cookie.
domain - String object containing the domain of the cookie to delete. This MUST
be the same as the domain used to create the cookie, or null/omitted if
no domain was specified when creating the cookie. */
复制代码 代码如下:
function DeleteCookie (name,path,domain) {
if (GetCookie(name)) {
document.cookie = name + "=" +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
"; expires=Thu, 01-Jan-70 00:00:01 GMT";
}
}
// Calling examples:
// var expdate = new Date ();
// FixCookieDate (expdate); // Correct for Mac date bug - call only once for given Date object!
// expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
// SetCookie ("ccpath", "http://www.dupcit.com/articles/", expdate);
// SetCookie ("ccname", "WebWoman", expdate);
// SetCookie ("tempvar", "This is a temporary cookie.");
// SetCookie ("ubiquitous", "This cookie will work anywhere in this domain",null,"/");
// SetCookie ("paranoid", "This cookie requires secure communications",expdate,"/",null,true);
// SetCookie ("goner", "This cookie must die!");
// document.write (document.cookie + "<br>");
// DeleteCookie ("goner");
// document.write (document.cookie + "<br>");
// document.write ("ccpath = " + GetCookie("ccpath") + "<br>");
// document.write ("ccname = " + GetCookie("ccname") + "<br>");
// document.write ("tempvar = " + GetCookie("tempvar") + "<br>");
相关推荐:
ChatGPT宕机两小时,OpenAI紧急修复,用户期待AI恢复正常服务,oppo小布ai
ChatGPT360:全方位提升你的工作与生活效率,ai72787
AI一键生成文章免费版:颠覆写作新体验
2025年整站SEO排名优化策略:让你的网站脱颖而出,id排版ai
文章去AI回归创作的本真之美
AI写作免费一键生成下载,助您轻松创作!
seo网站排名优化哪家好,seo网站优化平台 ,ai斗蟋
未来写作新模式文章撰写AI如何助力内容创作
“标题制造机”:颠覆内容创作的秘密武器,助你轻松打造吸引力十足的标题,景区线上推广用哪些网站
“只能写作”:在创作的世界里,选择文字,就是选择自由,云南关键词排名推广报价
AI一键生成原创文章,让创作更高效更轻松!
Bing搜索不能预览了?搜索引擎的新变革与挑战,ai制作一张窗花
优方法-高效生活与工作的秘密武器,钻石营销推广方案
SEO薪资这些,你也能月入过万!,天水网站建设公司
seo组建需要什么条件,seo建站的步骤 ,ai肌肉宝宝
为什么新手做seo好做,为什么要懂seo ,ai少女 3060显卡
seo简报什么意思,seo工作汇报 ,万花筒 ai
seo需要干什么,seo需要具备什么知识 ,ai梦境档案世岛大宅
专业SEO助力企业在激烈市场竞争中脱颖而出,嘉兴海外网站推广价格
SEO韩国:为您开启国际市场的增长之门,seo文章标题有哪些
SEO监控:精准把握网站排名与优化成效的利器,湖南seo排名商家名单
中文润色:提升表达的艺术,打造无懈可击的语言魅力,广告营销推广新思路论文
ChatGPT为什么用不了了?背后的真相揭秘!,ai写作专家收费吗
SEO做好,企业网站流量翻倍的关键,seo白帽技术有哪些
ChatGPT怎么打不开了?揭秘背后的原因与解决方法,ai中打开ai文件丢失
SEO与SEM策略:提升网站流量与品牌曝光的双剑合璧,ai补图
为什么做seo矩阵项目,为什么做seo矩阵项目不能做 ,怎么用ai写作
GPT怎么收费?揭秘AI技术的定价与价值,ai报考高考
SEO阶段解析:从入门到精通,助你站稳搜索引擎的前沿,网站建设特定开发
文章AI排版,让创作更高效的秘密武器
OpenAIGPT:开启智能时代的语言革命,ai辣妹动漫
亚马逊seo是什么公司的,“亚马逊” ,ai玩底特律
SEO百度优化:让你的品牌在搜索引擎中脱颖而出,日照网站推广策划
seo网络上什么意思,seo表示什么 ,如何避免今日头条ai写作检测
《*采集站:带你领略全球最全*资源的宝藏平台》,seo优化易下拉瞧瞧
ChatGPT维护页面-背后的技术与用户体验,ai领域ppt
SEO这种营销方式,改变你网站流量的秘密武器,佛山网站设计建设
用AI征文工具,轻松创作出精彩文章!
SEO详解:如何优化你的网站提升排名,获得更多流量,伊春湖南网站优化推广
ChatGPT免费用户每天的使用限制:如何高效利用,突破困境!,花花制作ai
优化服务网-提升客户体验,打造全方位智慧服务平台,东莞网站建设员招聘信息
什么是seo网站推广,什么是seo网站推广 ,ai酷男人
文章自动生成AI:助力写作新时代,让创作更高效
ChatGPT怎么突然不能打开了?你需要了解的原因与解决办法,ai写作有什么问题吗怎么解决
ChatGPTWindows版本下载:让AI助力您的工作和生活,ai yamama
AI免费生成:开启智能创作新纪元,助力你的创意无限可能
OpenAI无法验证支付方式?解决方案与常见问题解析,你好月光ai
seo要懂些什么,seo主要做什么的 ,小艾艾AI
ChatGPT故障:科技背后的秘密与应对策略,华为什么手机带ai功能
丹东seo是什么怎么选,丹东spr ,黑发ai图