How do I set a cookie for an iframe with a different domain?

跟風遠走 提交于 2019-12-12 01:16:21

问题


I need to construct a page that contains an iframe that in turn shows a page from an AWS service. Constructing a parent page that contains such an iframe is no problem. I need to access the DOM of the AWS page from the parent page but the Same Domain Policy prevents me from doing this so I have had to write code to serve as a proxy that fetches and returns the page HTML of the AWS service. So, my server returns the parent page which contains an iframe that in turn requests another page from my server which is the AWS service page HTML. Since the I-frame HTML is from the same Domain as the parent page the parent should be able to access the I-frame Dom.

The problem I am having is that the AWS service page requires cookies. When the parent page iframe requests the AWS service page HTML from my server I am unable to return the cookies with a domain that points to AWS. If I return the HTML with cookies where no domain is specified the cookies are created in the browser but they are associated with my server's domain and that won't work. If I set the cookies domain to be the AWS domain the cookies fail to be created. In both the Firefox and Chrome debugger I examine network traffic and see that the cookies are being transmitted to the browser but if the domain is for AWS the cookies are not created.

Research shows that this is a known issue that is related to the Same Domain Policy. If I understand correctly what I'm trying to do is set 3rd party cookie so I have (at least for testing purposes) made sure that both the Firefox and Chrome browsers allow third-party cookies but this still fails. The only suggestions that I have found for how to deal with this require that I have control over both servers and of course I have no access to the AWS servers.

How can I create these cookies so that the iframes AWS service page can access them?

Thank you.

来源:https://stackoverflow.com/questions/54030793/how-do-i-set-a-cookie-for-an-iframe-with-a-different-domain

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!