I wrote a content script that injects an iframe to any website (therefore different domain).

I need the parent website to send some information to the child iframe, however I couldn't find a way to do it.

The code

var targetFrame = $('#myIframe')[0];
targetFrame.contentWindow.postMessage('the message', '*');

Doesn't work somehow and i get a Cannot call method 'postMessage' of undefined error. But then when I tried the same code directly in Chrome's console, it worked.

I had no trouble sending a postMessage from the child to the parent though but just need a way for the parent to send messages to the child iframe.

Edit
Report