admin管理员组文章数量:1336357
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.
3 Answers
Reset to default 1I 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/
本文标签: send cookies to another web page with javascriptStack Overflow
版权声明:本文标题:send cookies to another web page with javascript - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742260168a2442365.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论