javascript iframe: accessing http from https
javascript iframe: accessing http from https
我有一个页面,它有一个iframe,可以从amazon aws s3 bucket加载html模板。在iframe中,我想获取父窗口的链接,然后添加一些参数。
E.g:我的父窗口有链接http://xx.xx.x.xxx:8088。我想获取这个url,append"#abc/edf"并重定向到那个页面。但我不能,因为我的iFrame有urlhttps://bucketName.s3.amazonaws.com
我得到的错误是
Uncaught SecurityError: Blocked a frame with origin "https://bucketName.s3.amazonaws.com" from accessing a frame with origin "http://xx.xx.x.xxx:8088". The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match.
我用来从iFrame 重定向到另一个页面的javascript
function navigateTo(e){
var destination = e.data.destination;
var url = window.parent.location.host;
window.parent.location.href = url+destination;
}
$("#button").click({destination: "/#abc/edf"}, navigateTo);
html
<div id="button"><a href="#">Redirect to another page</a></div>
我不能使用绝对路径是有原因的。父窗口链接将以某种方式更改。我认为最好的解决方案是获取父url并附加我想要的参数。如何在不出现安全错误的情况下实现此操作?
简短的回答是"你不能。"
浏览器安全模型排除了客户端的跨域和跨协议脚本。https协议下嵌入的iframe不允许访问(甚至不允许读取)其父级的非https上下文。
要执行您想要的操作,两个上下文必须在源域和协议上达成一致,以便在客户端进行交互。
相关文章:
- 关于引入外部javascript文件的问题&css通过https
- jquery ajax https调用给出ERR_INSECURE_RESPONSE
- 如何通过安全的https连接在javascript中使用基于soap xml的Web服务
- $https请求的安全性
- https.request ignoring rejectUnauthorized
- Validate JSON from Mongo?
- Get JSON from an url
- web配置http到https重定向异常
- creating objects from variables ES6
- getting id from jsp
- jquery使用name from变量按类选择元素
- HTML:从http到https发布表单
- Using jQuery with classes from ES6
- Node.js https获取请求ECONNRESET
- 如何计算与php中的CRC32函数兼容的arrayBuffer(javascript中的From FileReader)
- 如何删除'被按压'state from复选框
- 当我的所有 Ng-from 都有效时启用一个按钮
- PATCH https request from Parse
- javascript iframe: accessing http from https
- AJAX from HTTP to HTTPS