So, I have a page in DomainA, and using the Chrome extension, I insert some javascript that inserts an iframe that points to DomainB.
$("body").append("<iframe id='someFrame' src='http://www.domainB.com' width='300' height='800'></iframe>");
I also add some javascript to DomainA which is trying to get iframe contentWindow. I want to use the HTML5 postMessage api on it.
$("body").append("<a class='myLink'>Post Message</a>"); $(".myLink").click(function(){ var frameElem = document.getElementById("someFrame"); console.log("frameElem: " + frameElem); //succeeds var contentWin = frameElem.contentWindow; console.log("contentWin : " + contentWin); //undefined //can't do this since contentWin is undefined: //contentWin.postMessage("data", "*"); });
However, the contentWindow property is undefined. Why is this, and how can I get around this? If I add this extension code to a web page, it will work on its own.
Thanks!
(sorry cheesy jquery / javascript)
javascript google-chrome google-chrome-extension postmessage
Newtang
source share