跨域打開頁面: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"> 前后端分離 導致的 靜態頁面 加載