JavaScript Cookie函数
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JavaScript Cookie函数相关的知识,希望对你有一定的参考价值。
Simple functions to add, fetch or delete cookies in the browser via javascript.
function setCookie(c_name,c_value,c_expiredays,c_path,c_domain) { var c_exdate=new Date(); c_exdate.setDate(c_exdate.getDate()+c_expiredays); document.cookie=c_name+ "=" +escape(c_value)+((c_expiredays==null) ? "" : ";expires="+c_exdate.toUTCString()) +"; path="+ c_path +"; domain="+ c_domain; } function getCookie(tag) { var value = null var myCookie = document.cookie + ";" var findTag = tag + "=" var endPos if (myCookie.length > 0) { var beginPos = myCookie.indexOf(findTag) if (beginPos != -1) { beginPos = beginPos + findTag.length endPos = myCookie.indexOf(";",beginPos) if (endPos == -1) endPos = myCookie.length value = unescape(myCookie.substring(beginPos,endPos)) } } return value } function deleteCookie(cookie) { var yesterday = 24 * 60 * 60 * 1000 var expireDate = new Date() expireDate.setTime (expireDate.getTime() - yesterday) document.cookie =cookie + "=" + escape("nothing") + ";" + "expires" + "=" + expireDate.toGMTString() }
以上是关于JavaScript Cookie函数的主要内容,如果未能解决你的问题,请参考以下文章
如何将此 JavaScript 代码片段翻译成 Parenscript?