如何使用javascript在2个域中共享Cookie? [英] How do I share cookies across 2 domains with javascript?

查看:107
本文介绍了如何使用javascript在2个域中共享Cookie?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想要在example.com和mysite.com之间存取和设定Cookie。

I want to be able to access and set cookies between example.com and mysite.com. How do I do that?

推荐答案

您不能单独使用cookie:它们是明确设置的每个域,

You cannot do that with cookies alone: they are set explicitly per-domain, and there isn't a legitimate (read: "non-exploit") way to set them for another domain.

但是,如果您控制这两个服务器,则可以使用一些解决方法/ hack实现这一点,但很漂亮,它不是,它可能会意外断开(见这个问题;答案应该帮助你一个解决方案)。

However, if you control both servers, it may be possible to use some workarounds/hacks to achieve this, but pretty it isn't, and it may break unexpectedly (see this question; the answers there should help you to a solution).

这篇关于如何使用javascript在2个域中共享Cookie?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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