解决 Blocked a frame with origin “xxx“ from accessing a cross-origin frame

本文涉及的产品
.cn 域名,1个 12个月
简介: 解决 Blocked a frame with origin “xxx“ from accessing a cross-origin frame
  • 内嵌 iframe 页面,一般使用 window.parentwindow.top 来获取父页面的 window 对象
  • 在子页面 想使用(或传递给) 父页面的参数,但是原因两个的域名不一样,所以会出现跨域问题。
  • 解决办法
    1、父页面监听 message,写法固定
window.addEventListener('message', function (e) {
  console.log(e)
})
  • 2、子页面发送 message 消息,并附带参数
// window.parent 是 iframe 子页面获取父页面的 window 对象
// 后面的 * 号就是处理跨域问题的,任何域名都不会出现跨域问题
window.parent.postMessage("需要传递的参数", '*')
// 也可以指定传送域名地址,这个域名不会出现跨域问题,写父页面(接收)域名地址
window.parent.postMessage("需要传递的参数", 'http://0.0.0.0:8080')
相关文章
|
6月前
|
JavaScript 前端开发
has been blocked by CORS policy: The ‘Access-Control-Allow-Origin‘ header contains multiple values ‘
has been blocked by CORS policy: The ‘Access-Control-Allow-Origin‘ header contains multiple values ‘
148 0
|
API
【已解决】No ‘Access-Control-Allow-Origin‘ header is present on the requested resource
No ‘Access-Control-Allow-Origin‘ header is present on the requested resource
394 0
【已解决】No ‘Access-Control-Allow-Origin‘ header is present on the requested resource
|
11月前
|
安全 JavaScript 前端开发
No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
Uncaught DOMException: Blocked a frame with origin "http://localhost:8000" from accessing a cross-origin frame.
Uncaught DOMException: Blocked a frame with origin "http://localhost:8000" from accessing a cross-origin frame.
1162 0
|
Web App开发 安全 前端开发
Mixed Content: The page at was loaded over HTTPS, but requested an insecure imag
Mixed Content: The page at was loaded over HTTPS, but requested an insecure imag
464 0
Mixed Content: The page at was loaded over HTTPS, but requested an insecure imag
|
iOS开发 MacOS
curl: (4) A requested feature, protocol or option was not found
curl: (4) A requested feature, protocol or option was not found
273 0
curl: (4) A requested feature, protocol or option was not found
|
Java 应用服务中间件 Python
Refused to display 'xxx' in a frame ,because it set 'X-Frame-Options' to 'deny'.
我本是在DJANGO页面的iframe里嵌入springboot的页面。 当报了这个错误之后,我花了时间在nginx和django上, 后来才改变解决思路,从springboot出发,解决问题。
5845 0
|
Web App开发 安全
Not allowed to navigate top frame to data URL
Not allowed to navigate top frame to data URL
326 0
|
前端开发 数据可视化 Java
报错:跨域问题解决 No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
报错:跨域问题解决 No ‘Access-Control-Allow-Origin‘ header is present on the requested resource.
1286 0