send cookies to another web page with javascript - Stack Overflow

How can I send cookie on a page, to another page with JS?For example I have two pages:1 - www.domai

How can I send cookie on a page, to another page with JS?
For example I have two pages:
1 - www.domain1/admin.php
2 - www.domain2/getCookies.php
How can I send cookies from admin.php to getCookies.php and get them in this form :
getCookies.php?name=x&val=y
x is cookie name and y is the value of x.

How can I send cookie on a page, to another page with JS?
For example I have two pages:
1 - www.domain1./admin.php
2 - www.domain2./getCookies.php
How can I send cookies from admin.php to getCookies.php and get them in this form :
getCookies.php?name=x&val=y
x is cookie name and y is the value of x.

Share Improve this question asked Jan 1, 2012 at 17:46 Soroush KhosraviSoroush Khosravi 1901 gold badge2 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 1

I have done this in the past using JSONP. It will work in all browsers.

Simply read in the cookie values, craft a JSON string and send it across.

See http://www.ibm./developerworks/library/wa-aj-jsonp1/ for some examples.

You can not send cookies to different domain. Take a look at this for more detail:

  • How do I share cookies across 2 domains with javascript?
  • What's your favorite cross domain cookie sharing approach?

Use cross-document messaging (embed domain2 in an iframe and municate between domain1 website and domain2) if you want to do this in the browser, or if you can call domain2's server (and control it), you can use Cross-Origin Resource Sharing.

You'll find several libraries to make this kind of munication happen inside the browser at the top of this blog post (my post) if you want it to work for older browsers: http://softwareas./cross-domain-munication-with-iframes

If you're not worried about older browsers, you just need to send the cookie data along: document.getElementById("iframe").contentWindow.postMessage(cookieData, 'domain1.');

See John Resig's post for more details: http://ejohn/blog/postmessage-api-changes/

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742260169a4410757.html

相关推荐

  • send cookies to another web page with javascript - Stack Overflow

    How can I send cookie on a page, to another page with JS?For example I have two pages:1 - www.domai

    1天前
    30

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信