简体   繁体   English

Safari 不允许 iframe 中的跨域 cookie

[英]safari does not allowed cross-domain cookies in iframe

IE & Safari Browser blocks cross-domain cookies in an iframe. IE 和 Safari 浏览器阻止 iframe 中的跨域 cookie。

eg I have two websites, let's say they're example.com and anotherexample.net .例如,我有两个网站,假设它们是example.comanotherexample.net

On example.com , I have one page http://example.com/someform.asp and in this page i am using cookies.example.com ,我有一个页面http://example.com/someform.asp并且在此页面中我使用了 cookie。 When I open http://example.com/someform.asp directly in browser, it is working fine.当我直接在浏览器中打开http://example.com/someform.asp ,它工作正常。

On anotherexample.net , I have page http://anotherexample.net/page.asp , this page contains an IFRAME SRC="http://example.com/someform.asp" .anotherexample.net ,我有页面http://anotherexample.net/page.asp ,此页面包含IFRAME SRC="http://example.com/someform.asp" Now when we open http://anotherexample.net/page.asp page in browser, the cookies for example.com are not saved.现在,当我们在浏览器中打开http://anotherexample.net/page.asp页面时, example.com的 cookie 不会被保存。 In Firefox and chrome this problem doesn't appear.在 Firefox 和 chrome 中不会出现这个问题。

I found that using p3p policy we can fix this, but after setting below p3p policy in IIS response header and its works for IE only.我发现使用 p3p 策略我们可以解决这个问题,但是在 IIS 响应头中设置下面的 p3p 策略后,它仅适用于 IE。

P3P : CP="This is  a P3P policy! See  http://www.workplaceanswers.com/privacy-and-terms/"

But, I am still getting the same error in safari.但是,我在 safari 中仍然遇到同样的错误。 I have tried with different p3p policy values as below but not able to fix it.我尝试使用如下不同的 p3p 策略值,但无法修复它。

P3P : CP="CUR ADM DEV HIS TEL STA STP COM”
P3P:CP="IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT”
P3P:CP="IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA”

Is there any way to make this work in Safari?有什么办法可以在 Safari 中完成这项工作吗?

There is a solution posted by Vitaliy Ryepnoy at github: https://github.com/vitr/safari-cookie-in-iframe Vitaliy Ryepnoy在 github 上发布了一个解决方案: https : //github.com/vitr/safari-cookie-in-iframe

The gist: In the main window ( example.com ), you should detect if the browser is safari,if so, you redirect the user to iframe.com/fix_safari.html , where you set a cookie and redirect again to example.com .要点:在主窗口( example.com )中,您应该检测浏览器是否为 safari,如果是,则将用户重定向到iframe.com/fix_safari.html ,在其中设置 cookie 并再次重定向到example.com .

Then, safari let's you set a cookie in the iframe, because there is already a cookie there from iframe.com然后,safari 让你在 iframe 中设置一个 cookie,因为iframe.com那里已经有一个 cookie

worked for me, after hours of frustration经过数小时的挫折后,为我工作

more details and code example in the github page github页面中的更多详细信息和代码示例

Actually, I was suffered from cross domain cookie issue in safari web browser in mac & iPhone devices.实际上,我在 mac 和 iPhone 设备的 safari 网络浏览器中遇到了跨域 cookie 问题。 So, I was create one temp file on client machine and save all cookies in that temp file for One domain.因此,我在客户端计算机上创建了一个临时文件,并将所有 cookie 保存在该临时文件中,用于一个域。 And when I was try to read that cookies from another domain file then in that file i was made changes like if cookies are not set then fetch cookies data from that temp file And again set cookies for that second domain.当我尝试从另一个域文件中读取该 cookie 时,我在该文件中进行了更改,例如未设置 cookie 然后从该临时文件中获取 cookie 数据并再次为第二个域设置 cookie。 It's work successfully.它工作成功。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM