跨域打开页面:Uncaught DOMException: Blocked a frame with origin


Uncaught DOMException: Blocked a frame with origin

使用postMessage()方法可以解决跨域传值的问题
Api: https://developer.mozilla.org/zh-CN/docs/Web/API/Window/postMessage

父页面:

layer.open({
                skin: 'rocket',
                scrollbar: false,
                type: 2,
                title: 'test',
                shadeClose: true,
                area: ['50%', '50%'],
                content: url,//iframe的url
                btn:['保存'],
                btnAlign: 'c',
                yes: function(index, layero){
                    window[layero.find('iframe')[0]['name']].postMessage('addAndEdit', '*');
                    layer.close(index);
                },
                cancel: function(index, layero){
                    window[layero.find('iframe')[0]['name']].postMessage('addAndEdit', '*');
                    layer.close(index);
                }
            });
        

        function receiveMessage(event) {
            console.log(event.data)//取得子页面传回来的值
            var roomId = event.data;
            getSitUnitByRoomId(roomId)
        }

子页面:

// 跨域发送消息
		window.addEventListener('message',function(e){
			var value = e.data;
			//返回方法向父页面发送数据
			if (value != null && value == 'addAndEdit') {
				if (fangjianId) {
					parent.postMessage(fangjianId, "*")
				}
			}
		}, false);


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



猜您在找 iframe跨域问题:Uncaught DOMException: Blocked a frame with origin解决方法 Uncaught DOMException: Blocked a frame with origin "http://localhost 【运行错误】Uncaught DOMException: Blocked a frame with origin "null" from accessing a cross-origin frame. iframe跨源报错:"Blocked a frame with origin from accessing a cross-origin frame" 【记录】uni-app Chrome跨域解决方案插件 has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is... 解决本地浏览器运行项目时的跨域问题-Access to XMLHttpRequest at"xxx/xxx" from origin 'null' has been blocked by CORS policy 报CORS 跨域错误,提示 blocked by CORS policy"> 前后端分离 导致的 静态页面 加载