getcookies
setcookiesThis example creates a cookie with a specified name and value. The value is passed to the JScript escape function to ensure that the value only contains valid characters. When the cookie is retrieved, the JScript unescape function should be used to translate the value back to its original form.<SCRIPT>
// Create a cookie with the specified name and value.
// The cookie expires at the end of the 20th century.
function SetCookie(sName, sValue)
{
document.cookie = sName + "=" + escape(sValue) + ";
expires=Mon, 31 Dec 1999 23:59:59 UTC;";
}
</SCRIPT>
This example retrieves the value of the portion of the cookie specified by the sCookie parameter.<SCRIPT>
// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
} // a cookie with the requested name does not exist
return null;
}
</SCRIPT>
setcookiesThis example creates a cookie with a specified name and value. The value is passed to the JScript escape function to ensure that the value only contains valid characters. When the cookie is retrieved, the JScript unescape function should be used to translate the value back to its original form.<SCRIPT>
// Create a cookie with the specified name and value.
// The cookie expires at the end of the 20th century.
function SetCookie(sName, sValue)
{
document.cookie = sName + "=" + escape(sValue) + ";
expires=Mon, 31 Dec 1999 23:59:59 UTC;";
}
</SCRIPT>
This example retrieves the value of the portion of the cookie specified by the sCookie parameter.<SCRIPT>
// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
// cookies are separated by semicolons
var aCookie = document.cookie.split("; ");
for (var i=0; i < aCookie.length; i++)
{
// a name/value pair (a crumb) is separated by an equal sign
var aCrumb = aCookie[i].split("=");
if (sName == aCrumb[0])
return unescape(aCrumb[1]);
} // a cookie with the requested name does not exist
return null;
}
</SCRIPT>
解决方案 »
- 求教。
- 大家好,我是javascript初学者问个小问题
- insertRow对象事件
- 如何实现在图片上传之前对它调整大小、剪裁、生成缩略图(J2EE)
- 谁有jsp+javascript的动态树,每次只载入一级,有源码最好
- 怎么能在超连接后执行一段JS代码
- 在javascript中,可以设置下拉列表的readonly属性吗
- 如何扑捉键盘组合键,比如ctrl+q,ctrl+w...............
- Jquery get回调方法不执行。
- 不选择<option>
- 我想按F1不出现帮助,而是打开一个新窗口window.open(),帮我一下吧:-D
- 如何判断字符串长度,并由此决定td的长度,急!
//name:要读取的Cookie的名字
function getCookie (name) {
var presence =document.cookie.indexOf(name);
if (presence != -1) {
var start = presence + name.length + 1;
var end = document.cookie.indexOf(";", start);
if (end == -1)
end = document.cookie.length;
var value = document.cookie.slice(start, end);
return unescape(value);
}
else return false;
}