阅读在JavaScript中的cookie [英] Read cookie in javascript

查看:93
本文介绍了阅读在JavaScript中的cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的ASP code,可以在Javascript中做同样的?

 的HttpCookie饼干= this.Request.Cookies [投票];
如果(饼干!= NULL)
    如果(cookie.Values​​.Get(id.ToString())==真)返回true;
返回false;


解决方案

 函数readTheCookie(the_info)
{
//饼干加载到一个变量,它UNESCAPE VAR the_cookie =的document.cookie;
 VAR the_cookie = UNESCAPE(the_cookie);//值从cookie名称分开 VAR broken_cookie = the_cookie.split(一些参数); //参数取决于该cookie的存储方式
 VAR the_values​​ = broken_cookie [一些指数]; //你想要的价值指数
}

这是读一个cookie的所有部分,你可以使用这个片段来实现你想要的。

This is my asp code, can be the same done in Javascript?

HttpCookie cookie = this.Request.Cookies["Votes"];
if (cookie != null)
    if (cookie.Values.Get(id.ToString()) == "true")  return true;
return false;

解决方案

function readTheCookie(the_info)
{
// load the cookie into a variable and unescape it

 var the_cookie = document.cookie;
 var the_cookie = unescape(the_cookie);

// separate the values from the cookie name

 var broken_cookie = the_cookie.split("some parameter"); // parameter depends on how the cookie is stored
 var the_values = broken_cookie["some index"]; // index of the value that you want
}

These are all the parts of reading a cookie, you can use this snippet to achieve what you want.

这篇关于阅读在JavaScript中的cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆