我有一个iframe:
<iframe id="GameFrame"
sandbox="allow-scripts allow-pointer-lock"
src="https://127.0.0.1:112/games/1047/play">
</iframe>
我的父页面位于:
https://127.0.0.1/arcade/not-hidden/space-blaster-1047
我正在尝试向 iFrame 发送一条消息:
var gameIframe = $("#GameFrame");
gameIframe.get(0).contentWindow.postMessage("screenshot", "");
但是这会产生错误:
其他尝试:未捕获的SyntaxError:在调用“postMessage”时,目标起源无效''。
postMessage("screenshot", "https://127.0.0.1");
执行“postMessage”时失败,因为提供的目标源('https://127.0.0.1')与接收窗口的源('null')不匹配。
我如何将消息发送到iFrame中?