在 Safari 中设置跨域 cookie [英] Setting cross-domain cookies in Safari

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

问题描述

我必须从域 B.com 调用域 A.com(使用 http 设置 cookie).我在域 B.com 上所做的只是(javascript):

I have to call domain A.com (which sets the cookies with http) from domain B.com. All I do on domain B.com is (javascript):

var head = document.getElementsByTagName("head")[0];
var script = document.createElement("script");
script.src = "A.com/setCookie?cache=1231213123";
head.appendChild(script);

这会在我测试过的每个浏览器(Safari 除外)上设置 A.com 上的 cookie.令人惊讶的是,即使没有 P3P 标头,这也适用于 IE6.

This sets the cookie on A.com on every browser I've tested, except Safari. Amazingly this works in IE6, even without the P3P headers.

有什么办法可以在 Safari 中实现这个功能吗?

Is there any way to make this work in Safari?

推荐答案

来自 Safari 开发者常见问题解答:

Safari 附带了一个保守的 cookie 策略,该策略将 cookie 写入仅限于用户选择(导航到")的页面.此默认保守策略可能会混淆尝试写入 cookie 并失败的基于框架的站点.

Safari ships with a conservative cookie policy which limits cookie writes to only the pages chosen ("navigated to") by the user. This default conservative policy may confuse frame based sites that attempt to write cookies and fail.

我找不到解决这个问题的方法.

I have found no way to get around this.

如果值得的话,如果您使用 <script> 附加方法,Chrome 也不会设置 cookie,但是如果您有隐藏的 <img> 使用相同的来源,Chrome 可以与其他浏览器一起使用(Safari 除外)

If it's worth anything, Chrome doesn't set the cookies either if you use the <script> appending method, but if you have a hidden <img> with the same source, Chrome works in addition to the rest of the browsers (except, again, Safari)

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

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