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

推荐订阅源

GbyAI
GbyAI
D
DataBreaches.Net
博客园 - 三生石上(FineUI控件)
H
Hacker News: Front Page
Know Your Adversary
Know Your Adversary
Recorded Future
Recorded Future
The Hacker News
The Hacker News
Help Net Security
Help Net Security
月光博客
月光博客
L
LINUX DO - 热门话题
Hacker News - Newest:
Hacker News - Newest: "LLM"
T
Tor Project blog
Security Archives - TechRepublic
Security Archives - TechRepublic
aimingoo的专栏
aimingoo的专栏
Attack and Defense Labs
Attack and Defense Labs
Project Zero
Project Zero
V
Vulnerabilities – Threatpost
SecWiki News
SecWiki News
S
Security @ Cisco Blogs
Blog — PlanetScale
Blog — PlanetScale
V2EX - 技术
V2EX - 技术
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
A
Arctic Wolf
T
Threat Research - Cisco Blogs
WordPress大学
WordPress大学
H
Heimdal Security Blog
小众软件
小众软件
C
Check Point Blog
T
Tailwind CSS Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
C
Cyber Attacks, Cyber Crime and Cyber Security
Vercel News
Vercel News
云风的 BLOG
云风的 BLOG
Last Week in AI
Last Week in AI
L
LangChain Blog
博客园 - Franky
Martin Fowler
Martin Fowler
MongoDB | Blog
MongoDB | Blog
P
Proofpoint News Feed
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
J
Java Code Geeks
Apple Machine Learning Research
Apple Machine Learning Research
C
Cybersecurity and Infrastructure Security Agency CISA
C
CXSECURITY Database RSS Feed - CXSecurity.com
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
有赞技术团队
有赞技术团队
MyScale Blog
MyScale Blog
S
Schneier on Security

博客园 - Tobin

41岁的大龄程序员,苟着苟着,要为以后做打算了 UC_Center整合单点登录后远程注册不激活问题的解决办法 AspExe - a small ASP.NET compiler and executor for document generation 在as3中Embed(绑定)flash动画元素 - Tobin - 博客园 Embedding Resources with AS3 Configure the max limit for concurrent TCP connections [转]翻译:使用.net3.5的缓存池和SocketAsyncEventArgs类创建socket服务器 强制将IE,Chrome设置为指定兼容模式来解析(转) - Tobin - 博客园 工商银行,千万别用,转账不成功一样收手续费 MySQL vs NoSQL 效率与成本之争(转) 使用ASP.NET Global.asax 文件(转) [MySql识记]create utf8 database - Tobin npgsql连接postgresql数据库 由浅到深了解JavaScript类[转过来的收藏] javascript改变this指针 哪个美女最漂亮,自己写的js图片自适应切换 [图解] 你不知道的 JavaScript - “this”(转) 对与list<>泛型的一些操作方法 关于游戏开发中的A*/A-star的寻路算法的问题
javascript操作cookie实例
Tobin · 2008-07-08 · via 博客园 - Tobin

话我就不多说了,大家都能看懂,写的有点乱,帮别人写的,贴下来,以后忘了再用
代码实现功能:
1.点击登录保存cookie
2.刷新或重新打开页面读出cookie
3.点击delete 删除当前username下的cookie

没有完成的问题:
大家看到在setCookie方法里能设置许多东西,如过期时间,作用域,保存路径等,但由于对这几个参数改如何设置不太清楚,比如作用域就是页面的根域名,路径该保存成什么格式的,如果有谁知道,请告诉我哈,谢谢了

<!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>无标题文档</title>
<script type="text/javascript">
    
function GetCookieVal(offset)
//获得Cookie解码后的值
{
var endstr = document.cookie.indexOf (";", offset);
if (endstr == -1)
endstr 
= document.cookie.length;
return unescape(document.cookie.substring(offset, endstr));
}

function SetCookie(name, value)
//设定Cookie值
{
var expdate = new Date();
var argv = SetCookie.arguments;
var argc = SetCookie.arguments.length;
var expires = (argc > 2? argv[2] : null;
var path = (argc > 3? argv[3] : null;
var domain = (argc > 4? argv[4] : null;
var secure = (argc > 5? argv[5] : false;
if(expires!=null) expdate.setTime(expdate.getTime() + ( expires * 1000 ));
document.cookie 
= name + "=" + escape (value) +((expires == null? "" : ("; expires="+ expdate.toGMTString()))
+((path == null? "" : ("; path=" + path)) +((domain == null? "" : ("; domain=" + domain))
+((secure == true? "; secure" : "");
}

function DelCookie(name)
//删除Cookie
{
var exp = new Date();
exp.setTime (exp.getTime() 
- 1);
var cval = GetCookie (name);
document.cookie 
= name + "=" + cval + "; expires="+ exp.toGMTString();
}

function GetCookie(name)
//获得Cookie的原始值
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg)
return GetCookieVal (j);
= document.cookie.indexOf(" ", i) + 1;
if (i == 0break;
}

return null;
}

function get$(obj)
{
return document.getElementById(obj);
}

    
</script>
</head>
<body  onload="javascript:get$('username').value=GetCookie('Page')==null?'':GetCookie('Page');get$('password').value=GetCookie(GetCookie('Page'))==null?'':GetCookie(GetCookie('Page'));">
<table width="580" border="0" align="center">
  
<tr>
    
<td width="114">&nbsp;</td>
    
<td width="456">&nbsp;</td>
  
</tr>
  
<tr>
    
<td>用户名:</td>
    
<td><input type="text" name="username" id="username"/></td>
  
</tr>
  
<tr>
    
<td>密码</td>
    
<td><input type="text" name="password" id="password" /></td>
  
</tr>
  
<tr>
    
<td><input type="button" name="Submit" value="登陆" onclick="SetCookie('Page',get$('username').value);SetCookie(get$('username').value,get$('password').value);"/></td>
    
<td><input type="button" value="delete" onclick="DelCookie(GetCookie('Page'));DelCookie('Page');get$('username').value='';get$('password').value='';"/></td>
  
</tr>
</table>

</body>
</html>