【发布时间】:2014-09-05 02:14:50
【问题描述】:
我有一个页面,它有一个 iframe,它从亚马逊 aws s3 存储桶加载 html 模板。在iframe中,我想取父窗口的链接,然后添加一些参数。
例如:我的父窗口有链接 http://xx.xx.x.xxx:8088 。我想获取此网址,附加“#abc/edf”并重定向到该页面。但我不能,因为我的 iFrame 有 url https://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 并附加我想要的参数。如何在不出现安全错误的情况下实现这一点?
【问题讨论】:
标签: javascript html iframe amazon-s3