javascript - 需要更改嵌套Windows的Parent URL

标签 javascript iframe window.parent

我目前有一个表单正在 iFramed 到充当搜索栏的应用程序中。当用户在此搜索中按 Enter 键时,表单会将父窗口重定向到应用程序内的不同 URL。请注意,它们具有相同的域,但具有不同的子域。这部分效果很好。请参阅下面的代码。

window.parent.location = redirectUrl;

问题是我有一位客户正在将此应用程序 iFraming 到另一个应用程序中。当他们在这种情况下执行此搜索时,我们收到一条错误,指出“尝试导航的框架既不是与目标同源,也不是目标的父级或开启者。”

是否有解决方法可以使其正常工作?

最佳答案

如果域不同,浏览器通常会不允许这样做。

您也许可以设置响应 header 来告诉浏览器允许请求通过:

Access-Control-Allow-Origin: http://example.com

见下文: http://www.staticapps.org/articles/cross-domain-requests-with-cors

关于javascript - 需要更改嵌套Windows的Parent URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32127002/

相关文章:

javascript - 素面 : get geocoder address from google Map to ManagedBean

javascript - 如何在 ng-repeat 循环中分配一个 angularjs 事件监听器?

javascript - react 组件 Prop 中的流泛型

javascript - 使用 JavaScript 滚动 iframe?

javascript - IE8+, window.open(url/#/frag ,'_parent' ) 与 iframe 中的parent.location.href=url/#/frag

javascript - 动态添加图像的加载事件不会触发

Firefox 后退按钮与 iframe

javascript - 嵌入网页的 Vimeo 导致错误

javascript - window.parent.location.href IE9 Bug?