gpt4 book ai didi

html - 无法在 'postMessage' : Invalid target origin 上执行 'Window'

转载 作者:搜寻专家 更新时间:2023-10-31 08:17:23 27 4
gpt4 key购买 nike

我有 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", "");

但这会引发错误:

Uncaught SyntaxError: Failed to execute 'postMessage' on 'Window': Invalid target origin '' in a call to 'postMessage'.

其他尝试:

postMessage("screenshot", "https://127.0.0.1");

Failed to execute 'postMessage' on 'DOMWindow': The target origin provided ('https://127.0.0.1') does not match the recipient window's origin ('null').

我怎样才能将此消息发布到 iFrame?

最佳答案

刚想出来,需要用*作为原点:

gameIframe.get(0).contentWindow.postMessage("screenshot", "*");

关于html - 无法在 'postMessage' : Invalid target origin 上执行 'Window',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29918350/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com