iframe中的Safari和Cookie [英] Safari and cookies in iframe
问题描述
Safari浏览器默认情况下会阻止第三方Cookie。
Safari browser blocks 3rd party cookies by default.
我有网站A(主网站)将网站B(框架网站)加载到iframe中。站点B设置了一些cookie(当用户单击按钮时),以使其正常运行。这些cookie称为第三方cookie,因为它们不是由站点A设置的。
I have site A (main site) that loads site B (framed site) in the iframe. Site B sets some cookies ( WHEN THE USER CLICK A BUTTON ), to function properly. These cookies are called 3rd party cookies, as they are not set by site A.
所以我找到了以下解决方案: https://github.com/vitr/safari-cookie-in-iframe
So I found this solution: https://github.com/vitr/safari-cookie-in-iframe
但是在我的情况下,这是行不通的,因为要设置cookie,用户首先必须单击一个按钮。
But in my case it doesn't work because to set the cookie, the user first has to click a button.
framed.html实际上就像
The framed.html is infact like this:
<!DOCTYPE html>
<html>
<head>
<title>Framed Page</title>
</head>
<body style="background-color: lightcoral;">
<h2>This is the framed site</h2>
<div border="0" class="cookie_button" id="continue_button" onclick="SetCookie('cookieAcceptanceCookie','accepted',9999);">accept</div>
</body>
</html>
我的问题是否可以解决?
Is there a solution to my problem?
推荐答案
唯一适用于我的解决方法是通过iframed域重定向一次。
The only workaround that worked for me is redirecting through the iframed domain once.
因此,如果您有abc.com并且xyz.com是abc.com下的iframe,而登陆到abc.com时,仅出于设置空白Cookie的目的,就需要通过xyz.com进行中间重定向。然后Safari允许通过iframe为xyz.com设置Cookie。
So, if you have abc.com and xyz.com is an iframe under abc.com, while landing to the abc.com, there needs to be an intermediate redirect through xyz.com only for the purpose of setting a blank cookie. Then Safari will allow setting a cookie from iframe for xyz.com.
我不确定是否还有其他更好的解决方法。但是,这有效并达到了我的目的。
I'm not sure if there's any other better workaround. However, this worked and served my purpose.
谢谢。
这篇关于iframe中的Safari和Cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!