惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
Secure Thoughts
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
S
Securelist
云风的 BLOG
云风的 BLOG
M
MIT News - Artificial intelligence
Engineering at Meta
Engineering at Meta
雷峰网
雷峰网
C
CERT Recently Published Vulnerability Notes
H
Hackread – Cybersecurity News, Data Breaches, AI and More
S
SegmentFault 最新的问题
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
K
Kaspersky official blog
WordPress大学
WordPress大学
I
Intezer
L
Lohrmann on Cybersecurity
V
Vulnerabilities – Threatpost
C
Check Point Blog
A
About on SuperTechFans
AWS News Blog
AWS News Blog
Latest news
Latest news
宝玉的分享
宝玉的分享
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
小众软件
小众软件
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
C
Cyber Attacks, Cyber Crime and Cyber Security
SecWiki News
SecWiki News
Recorded Future
Recorded Future
Last Week in AI
Last Week in AI
D
Darknet – Hacking Tools, Hacker News & Cyber Security
The Register - Security
The Register - Security
A
Arctic Wolf
V2EX - 技术
V2EX - 技术
Hacker News: Ask HN
Hacker News: Ask HN
V
V2EX
Scott Helme
Scott Helme
I
InfoQ
Project Zero
Project Zero
Security Archives - TechRepublic
Security Archives - TechRepublic
Recent Announcements
Recent Announcements
Spread Privacy
Spread Privacy
Attack and Defense Labs
Attack and Defense Labs
大猫的无限游戏
大猫的无限游戏
Webroot Blog
Webroot Blog
N
News and Events Feed by Topic
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
The GitHub Blog
The GitHub Blog
NISL@THU
NISL@THU
L
LangChain Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com

博客园 - singleblue

IIS7 asp.net配置默认文档的错误 画图工具 UI层方案征集 B/S项目架构探讨 如何做自动录入数据功能 Failed to execute request because the App-Domain could not be created 解决ie7以下浏览器PNG图片背景不透明且链接失效的办法 拼接字符串的效率(转载) 最近准备用的数据访问类,欢迎拍砖! 关于JSON的文章 求助:如何合并两个PDF文档 取水晶报表的总页数 javascript全角半角问题 以支持多种浏览器的方式创建XMLHttpRequest对象 四种引用 使用AjaxPro与Session交互时遇到一个问题 window.print() 急求datastage 控件隐藏(Visible=false)的一个问题
javascript操作cookie
singleblue · 2008-06-11 · via 博客园 - singleblue

<!--
//学习一下如何利用js来操作cookie

//写入 cookie
//不区分 cookieName 的大小写
//不考虑子键
function WriteCookies(cookieName, cookieValue, expires)
{
    if (expires)
    {
        //指定了 expires
        document.cookie = 
            WriteCookies_GetCookieName(cookieName) + "=" + escape(cookieValue) 
            + "; expires=" + xpires.toGMTString();
    }
    else
    {
        document.cookie = WriteCookies_GetCookieName(cookieName) + "=" + escape(cookieValue);
    }
}

//获取并返回与 cookieName 同名的 cookie 名称,允许大小写不同
//如果不存在这样的 cookie,就返回 cookieName
function WriteCookies_GetCookieName(cookieName)
{
    var lowerCookieName = cookieName.toLowerCase();
    var cookieStr = document.cookie;
   
    if (cookieStr == "")
    {
        return cookieName;
    }
   
    var cookieArr = cookieStr.split("; ");
    var pos = -1;
    for (var i=0; i<cookieArr.length; i++)
    {
        pos = cookieArr[i].indexOf("=");
        if (pos > 0)
        {
            if (cookieArr[i].substring(0, pos).toLowerCase() == lowerCookieName)
            {
                return cookieArr[i].substring(0, pos);
            }
        }
    }
   
    return cookieName;
}

//获取并返回 cookie 值
//不区分 cookieName 的大小写
//dfltValue 为默认返回值
//不考虑子键
function ReadCookies(cookieName, dfltValue)
{
    var lowerCookieName = cookieName.toLowerCase();
    var cookieStr = document.cookie;
   
    if (cookieStr == "")
    {
        return dfltValue;
    }
   
    var cookieArr = cookieStr.split("; ");
    var pos = -1;
    for (var i=0; i<cookieArr.length; i++)
    {
        pos = cookieArr[i].indexOf("=");
        if (pos > 0)
        {
            if (cookieArr[i].substring(0, pos).toLowerCase() == lowerCookieName)
            {
                return unescape(cookieArr[i].substring(pos+1, cookieArr[i].length));
            }
        }
    }
   
    return dfltValue;
}


//test all the oper

document.write("写入名称为 cv 的 cookie...<br>");
WriteCookies("test", "test123", null);

document.write("写入名称为 Ab,带失效日期的 cookie...<br>");
var expires = new Date("December 11, 2010");
WriteCookies("singleblue", "test234", expires);

document.write("读取名称为 singleblue 的 cookie..." + ReadCookies("ab", ""));
-->