欢迎您访问 最编程 本站为您分享编程语言代码,编程技术文章!
您现在的位置是: 首页

实际应用:iframe之间的通讯技巧

最编程 2024-01-31 13:19:25
...
<iframe src="http://localhost:8091" id="receiver" width="100%" height="100%" /> window.addEventListener( "message", function(e) { // 监听 message 事件 console.log(e.origin); if (e.origin == 'http://localhost:8091') { // 验证消息来源地址 console.log(e.data); const { type, data } = e.data; try { if (type === "addPart") { eventBus.$emit("direct-add-part", JSON.parse(data)); } } catch (error) { console.log(error); } return; } }, false );

推荐阅读