Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I have the 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'm trying to post a message to the iFrame:

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

But this throws the error:

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

Other attempts:

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').

How can I get this posting a message to the iFrame?

like image 714
Tom Gullen Avatar asked Apr 28 '15 11:04

Tom Gullen


1 Answers

Just figured this out right now, need to use * as the origin:

gameIframe.get(0).contentWindow.postMessage("screenshot", "*");
like image 68
Tom Gullen Avatar answered Sep 22 '22 03:09

Tom Gullen