如何在 Safari 中的 iframe 内设置来自外部域的 cookie? [英] How do I set cookies from outside domains inside iframes in Safari?

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

问题描述

来自 Apple 开发者常见问题

Safari 带有一个保守的限制 cookie 的 cookie 政策只写入选定的页面(导航到")由用户.

Safari ships with a conservative cookie policy which limits cookie writes to only the pages chosen ("navigated to") by the user.

默认情况下,Safari 只允许来自您直接导航到的站点的 cookie.(即,如果您点击带有该域名网址的链接).

By default Safari only allows cookies from sites you navigate to directly. (i.e. if you click on links with the url of that domainname).

这意味着,如果您使用 iFrame 加载来自您自己站点的页面以及来自其他站点的页面,则其他站点无法设置 cookie.(例如,售票处).一旦您直接访问了另一个域,另一个站点就可以访问和更改自己的 cookie.

This means that if you load a page from your own site with an iFrame with a page from another site, that the other site is not able to set cookies. (for instance, a ticketshop). As soon as you have visited the other domain directly, the other site is able to access and change its own cookies.

在无法访问其他站点上的代码的情况下,如何使用户体验尽可能不引人注目?

Without having access to code on the other site, how can i make the user-experience as inobtrusive as possible?

是否有(javascript?)方法来检查其他站点的 cookie已设置,因此,如果需要,首先显示指向其他站点的直接链接?

Is there a (javascript?) way to check if the other site's cookies are already set, and accordingly, show a direct link to the other site first, if needed?

更新:

HTML5 功能window.postmessage"似乎是一个不错的解决方案.
有一些 jQuery 库可能会有所帮助,并且与最新的浏览器兼容.
本质上,iFrame 文档通过 window 元素使用 Json 发送消息.

The HTML5 feature 'window.postmessage' seems to be a nice solution.
There are some jQuery libraries that might help, and compatible with most recent browsers.
In essence, the iFrame document sends messages, with Json, thru the window element.

非常好的 Postmessage-plugin,由 daepark 提供,我开始工作了.
和另一个 jQuery postMessage,我发现了 Ben Alman,但尚未测试.

The very nice Postmessage-plugin, by daepark, which i got working.
and another jQuery postMessage, by Ben Alman i found, but haven't tested.

推荐答案

localStorage 受 safari 和所有现代浏览器的支持,甚至允许对加载到 iframe 的页面进行读/写操作.如果您不介意放弃对 ie6 和 ie7 的支持,请尝试在您的框架站点中使用 localStorage 而不是 cookie.我知道您的问题特别说明您无权访问框架站点上的代码,但对于那些访问代码的人来说,localStorage 绝对解决了safari iframe 中没有 cookie"的问题.

localStorage, supported by safari and all modern browsers, permits read/write operations even on pages loaded into iframes. if you don't mind dropping support for ie6 and ie7, try using localStorage instead of cookies in your framed site. i know your question specifically says you don't have access to code on the framed site, but for those who do, localStorage definitely solves the "no cookies in a safari iframe" problem.

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

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