参考MDN: https://developer.mozilla.org/zh-CN/docs/Web/API/Window/postMessage
一、发送端
1.发送消息的基本语法
targetWindow.postMessage(message, targetOrigin, [transfer])
2.targetWindow及参数说明
① targetWindow 表示接收消息的窗口的引用。获得该引用的方法包括:
Window.open
Window.opener
HTMLIFrameElement.contentWindow
Window.parent
Window.frames +索引值
② message 表示发送端发送给接收端的消息
③ targetOrigin 表示能接收到消息事件的窗口
其值可以是字符串"*"(表示无限制)或者一个 URI。
④ transfer 可选,是一串和 message 同时传递的 Transferable 对象。这些对象的所有权将被转移给消息的接收方,而发送一方将不再保有所有权。
3.示例
const targetWindow = window.