Blocked a frame with origin “https://my.xxxxxxx.com“ from accessing a cross-origin frame.
最近在写一个项目:需要在页面使用iframe来做登陆功能,本想使用parent.window.location.reload();刷新页面的,最后报错了“Blocked a frame with origin "https://my.xxxxxxx.com" from accessing a cross-origin frame”。
很明显这个报错就是跨域的问题,因为iframe遵循"同源策略",所以在不同源的情况下是无法进行DOM操作的。因为我只是需要刷新父级的页面所以我使用了:parent.window.location.href = document.referrer;用来在子级窗口刷新父的页面。
如果需要进行DOM操作或者传参的可以使用 postMessage() 方法用于安全地实现跨源通信,如下:
父级页面:
<div style="margin-bottom: 20px;">
<button οnclick="handleEvent()">向子页面发送信息</button>
</div>
<iframe src="iframe.html" id="iframe"></iframe>
<script>
function handleEvent() {
// iframe的id
var f = document.getElementById('iframe');
// 触发子页面的监听事件
f.contentWindow.postMessage('父页面发的消息', '*');
}// 注册消息事件监听,接受子元素给的数据
window.addEventListener('message', (e) => {
console.log(e.data);
}, false);
</script>
子窗口:
<button οnclick="handleEvent()">向父页面发送信息</button>
<p>子页面</p>
<script>
// 注册消息事件监听,接受父元素给的数据
window.addEventListener('message', (e) => {
console.log('iframe=' + e.data);
}, false);function handleEvent() {
// 向父页面发消息
window.parent.postMessage('子页面发的消息', '*');
}</script>
Blocked a frame with origin “https://my.xxxxxxx.com“ from accessing a cross-origin frame.相关推荐
- Access to script at ‘xxx‘ from origin ‘null‘ has been blocked by CORS policy: Cross origin requests
前言 本地调试js时,遇到本错误 Google Chrome 84.0.4147.135 (正式版本) (64 位) (cohort: Stable Installs Only) 修订版本 c42bd ...
- 【VSCode】from origin ‘null‘ has been blocked by CORS policy: Cross origin requests are only supported
Access to script at 'file:///C:/Users/dawulei/Desktop/%E9%A1%B9%E7%9B%AE/%E5%9D%A6%E5%85%8B%E5%A4%A7 ...
- ajax跨域请求问题:Access to XMLHttpRequest at……has been blocked by CORS policy: Cross origin requests
背景:本地代码调试时,加载本地资源正常,jquery的AJAX请求服务端资源报错. Access to XMLHttpRequest at '***** ' from origin 'null' ha ...
- 解决Cross origin requests are only supported for protocol schemes问题
解决Cross origin requests are only supported for protocol schemes问题 问题描述 本前端小白在学习的时候尝试按照一个网上的blog的代码来跑 ...
- 【跨域异常】Cross origin requests are only supported for protocol schemes: http, data, chrome,chrome-exten
一.背景描述 下面是我用ajax异步请求时的写法,请注意url是怎么写的,下面的错误就是由于这个url的写法导致的. // 获取省份列表 $(document).ready(function () { ...
- Jetty Cross Origin Filter解决jQuery Ajax跨域访问的方法
当使用jQuery Ajax post请求时可能会遇到类似这样的错误提示 XMLHttpRequest cannot load http://xxxxxx. Origin http://xxxxxx ...
- 【chrome错误】Cross origin requests are only supported for protocol schemes: http, data,chrome-extension
使用ajax请求本地文件,chrome会报跨域错误:XMLHttpRequest cannot loadfile:///C:/Users/Li/Desktop/images/alist.json.Cr ...
- [NodeJS] Jest 环境下 Axios 请求报错: Cross origin http://localhost forbidden
文章目录 问题概述 解决方案 参考 本博客站点已全量迁移至 DevDengChao 的博客 https://blog.dengchao.fun , 后续的新内容将优先在自建博客站进行发布, 欢迎大家访 ...
- Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, edge
Cross origin requests are only supported for protocol schemes: http, data, chrome-extension, edge, h ...
最新文章
- javascript高级程序设计第一章
- 反转 鼠标_梦幻西游:剧情反转?挖图挖出环装,在晶清加持下3000W到手
- Mybatis工作流程,附带mybatis的mapper文件和config配置文件模板。mapper文件和dao接口的关系——xml中的namespace和sql标签id命名要求。
- 关系代数的自然连接符号_初中数学知识清单之代数式的认识
- SON_EXAM考试php,通用全国少儿英语等级考试:三星笔试真题
- 关于Ubuntu中 E: Could not get lock /var/lib/dpkg/lock - open (11: Resource temporarily unavailable)解决方案
- LNMP 1.2 Nginx编译安装
- Lwip协议详解(基于Lwip 2.1.0)TCP协议 (未完待续)
- 35张动图:关于机房空调水冷系统和风冷系统
- 图文展示目标检测的现代发展历史
- 转载 SpringMVC详解(一)------入门实例
- 云原生与业务可观测性
- 上海七宝惊现海宝美眉
- Mobile2.0不对等的战争
- PPT制作技巧汇总之图形对象与多媒体应用(office 2007)
- CDN工作原理及淘宝双十一图片访问实战
- matlab-频响函数
- linux/windows下基于opc ua协议使用open62541开发客户端-上
- springcloud gateway 整合swagger3.0.0
- Docker・3th 常用命令
热门文章
- 【项目记录】Linux日志审计系统
- php的登录页面怎么弄,php登录界面_php简单登录页面
- EMC的PCB设计技术。(分层、布局、布线)
- 联想集群超算LICO初次使用踩坑说明(遇到的错误,一些使用方法和singularity新建容器方法)
- 常见的无法上网故障原因和解决方法
- 【Sublime Text 3】Sublime Text 3 - cracked 3083\3085
- Linux 中去除 vi/vim 和 git diff 中的 ^M 问题解决办法
- 计算机在机械智能制造中的应用,数控技术在智能制造中的应用及发展
- 矩阵相关操作和矩阵快速幂
- SSDP 服务发现协议