在 jquery 中读取 cookie 值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7515061/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
read cookie value in jquery
提问by user959128
I have called one php page inside the iframe
我在 iframe 中调用了一个 php 页面
I have stored some values in cookies.I want to read that cookies values from that page to other page.
我在 cookie 中存储了一些值。我想从该页面到其他页面读取 cookie 值。
I used jQuery to read cookie.
我使用 jQuery 来读取 cookie。
var value = $.cookie('artname');
'artname' is the cookie name.
'artname' 是 cookie 名称。
But it displaying null value because cookies path is different,path is "/v/abcfile/frontend/".
但它显示空值,因为cookies路径不同,路径是 "/v/abcfile/frontend/".
But the path for the other cookies on the page i am trying to get is "/.
但是我试图获取的页面上其他 cookie 的路径是“/.
I tried with this: top.jQuery.cookie('artname');
Its still showing me the same.
我试过这个:top.jQuery.cookie('artname');
它仍然显示我相同。
how can I get value of cookie?
我怎样才能获得cookie的价值?
回答by nWorx
just use the path property
只需使用 path 属性
$.cookie("example", { path: '/' });
http://www.electrictoolbox.com/jquery-cookies/
http://www.electrictoolbox.com/jquery-cookies/
cheers
干杯