iframe页面嵌套数据问题:
引入该博主的技术观点,感谢
链接地址 https://juejin.cn/post/7069972084654342174
https://developer.mozilla.org/zh-CN/docs/Web/API/Window/postMessage
https://blog.csdn.net/monkindey/article/details/23659387
window.parent.postMessage({data:{ status:200 }}, "http://localhost:3001/")
let b_win = document.getElementsByClassName('iframeWorkFlowAssignResourceClassName')[0].contentWindow
b_win.addEventListener("tReady", function(e){
var msg = e.detail.msg
console.log(e,"getmsgaaa:" + msg)
openDialog.value = false
})
setTimeout(function(){
console.log(1,'1S过后再触发dispatchEvent');
// 1,创建事件对象
var bEvent = new CustomEvent("tReady", {
detail: {
msg: "7000ms ok",
doc: document
},
bubbles: true,// 是否冒泡
cancelable: true// 是否可以取消事件的默认行为
});
console.log("1s过后触发浏览器广播事件asd",window.location.protocol+'//'+window.location.hostname+':7779');
window.parent.postMessage({data:{ status:200 }}, "http://localhost:3001/")
// window.parent.postMessage('一个测试信息', "")
// window.parent.postMessage(bEvent, '*');
// window.parent.postMessage('removeSession', window.location.protocol+'//'+window.location.hostname+':7779');
// window.dispatchEvent(bEvent);
}.bind(this), 1000)