var _this = this;
const iframe = document.querySelector("#iframeId");
// 处理兼容行问题
if (iframe.attachEvent) {
iframe.attachEvent("onload", function () {
// iframe加载完毕以后执行操作
console.log("iframe已加载完毕");
let data = {
action: "sendMessage",
content: {msg:'发送消息'}
};
var contentWindow = document.getElementById("eventDetailMap").contentWindow;
contentWindow.postMessage(JSON.stringify(data), this.iframeURL);
});
} else {
iframe.onload = function () {
// iframe加载完毕以后执行操作
console.log("iframe已加载完毕");
let data = {
action: "sendMessage",
content: {msg:'发送消息'}
};
var contentWindow = document.getElementById("eventDetailMap").contentWindow;
contentWindow.postMessage(JSON.stringify(data), this.iframeURL);
};
}
iframe加载完后再给iframe发送消息
最新推荐文章于 2024-08-08 22:17:44 发布