跨协议cookie iFrame [英] Cross protocol cookie iFrame

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

问题描述

我在 http ://localhost/mySite/Page1.aspx上有一个网页,其中包含具有src https :// localhost / mySite / Page2的iframe。 aspx。

I have a web page on http://localhost/mySite/Page1.aspx that contains an iframe with src https://localhost/mySite/Page2.aspx.

在iframe页面(Page2.aspx)中,我使用JavaScript设置cookie。如何在父页面(Page1.aspx)上读取该Cookie?看起来Page1没有看到Page2设置的Cookie。

Inside iframe page (Page2.aspx), i set cookie with JavaScript. How i can read that cookie on parent page (Page1.aspx)??? It looks like Page1 not sees the cookie that Page2 sets.

要设置/读取Cookie,我使用jQuery.Cookie插件:

To set/read cookies, I use jQuery.Cookie plugin:

$.cookie('myKey', JSON.stringify(data), { expires: 1, path: '/', domain: 'localhost' });

BTW,如果有人能给我一个想法如何在客户端上传输数据,很高兴知道它(服务器池不是我的解决方案)。
我发现它与sessionStorage / localStorage一起使用,但它只适用于IE:(

BTW, if someone can give me an idea how to transfer data on client in such scheme, i will glad to know about it (Server pooling not a solution for me). I found it works with sessionStorage / localStorage, but it works only in IE :(

推荐答案

评论:

问题是由于同源政策(SOP),其禁止不同来源的内容彼此干扰。不同的来源不仅仅是基于域的比较,它还基于使用的协议,因为它是因此, http:// localhost 是不同的起源到 https:// localhost

The issue is due to the Same Origin Policy (SOP), which forbids contents of different sources from interfering with one another. different sources is not only based on the comparison of domains, it is also based on the protocol in use as it is clearly shown on this Wikipedia page. Thus, http://localhost is a different origin to https://localhost.

为了使这两个来源能够沟通:

In order to make these two sources able to communicate:


  • 此链接完美地描述了常用的技术(iframe代理和网址轮询),并在其物理定律:您可以使用IFrames做什么段落中清楚地总结SOP的规则。

  • 这篇其他文章文章(从上面的文章)将常见的技术合并到一个优雅的解决方案

  • ,以便目标浏览器都符合HTML5(即最新的和标准的浏览器,即不是大多数MSIE版本),该标准引入了一个新的帧间通信系统 window.postMessage() onMessage 事件

  • this link perfectly describes the commonly used techniques (iframe proxies & URL polling), and intelligibly sums up the rules of the SOP in its paragraph "The Laws of Physics: what you can do with IFrames"
  • this other well-documented article (linked from the article above) merges the usual techniques into an elegant solution
  • in case the targeted browsers are all HTML5-compliant (i.e. up-to-date-and-to-standards browsers, i.e. not most MSIE versions), this standard introduced a new inter-frame communication system with window.postMessage() and the onMessage event

还有免费的预构建解决方案未测试),如 Ternarylabs的舷窗 EasyXDM

There are also free pre-built solutions (which I didn't tested though), like Ternarylabs' Porthole or EasyXDM.

干杯!

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

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