好吧,无聊的时候就发下博客,记录最近的心得
核心代码
document.cookie = sName + “=” + escape(sValue) + “;domain=.abc.com; expires=Fri, 31 Dec 2016 23:59:59 GMT; path=/”
完整代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
<script language="javascript" type="text/javascript"> function SetCookie(sName, sValue) { var a=sValue; document.cookie = sName + "=" + escape(sValue) + ";domain=.abc.com; expires=Fri, 31 Dec 2016 23:59:59 GMT; path=/" } function GetCookie(sName) { var aCookie = document.cookie.split("; "); for (var i=0; i < aCookie.length; i++) { var aCrumb = aCookie[i].split("="); if (sName == aCrumb[0]) return unescape(aCrumb[1]); } return 0; } function DelCookie(name) { var exp = new Date(); exp.setTime(exp.getTime() - 1); var cval=GetCookie(name); if(cval!=null) document.cookie= name + "="+cval+";expires="+exp.toGMTString(); } function changeWindow(){ var widthh = document.body.clientWidth; if(widthh < 1002){ document.getElementById("mybody").className='width1002'; } } </script> |
效果,所有abc.com的二级域名均可以实现共享cookie,可以做一些登录相关的事情
Latest posts by Zhiming Zhang (see all)
- aws eks node 自动化扩展工具 Karpenter - 8月 10, 2022
- ReplicationController and ReplicaSet in Kubernetes - 12月 20, 2021
- public key fingerprint - 5月 27, 2021