Failed to execute "postMessage" on "Window": Invalid target origin

I have an iframe:

<iframe id="GameFrame" 
sandbox="allow-scripts allow-pointer-lock" 
src="https://127.0.0.1:112/games/1047/play">
</iframe>

      

My parent page is located at:

https://127.0.0.1/arcade/not-hidden/space-blaster-1047

      

I am trying to post to an iFrame:

var gameIframe = $("#GameFrame");
gameIframe.get(0).contentWindow.postMessage("screenshot", "");

      

But this throws an error:

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

Other attempts:

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

      

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

How can I send this message to an iFrame?

+3


source to share


1 answer


Just figured it out now, needs to be used *

as source:



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

      

+2


source







All Articles