I use a few lines of javascript to create an iframe element, and then I\'d like to send it a message, like this:
function loadiframe (callback) {
var body =
There are two possible problems:
callback
before the child frame has loaded - try it in the load
event or do it in a setTimeout
postMessage
to work with anything other that '*' as the origin. If I put a URL in there I get a security warning "Security Error: Content at http://xxx/ may not load data from http://yyy/", except only in the error console (Ctrl + Shift + J) not in any other place. I suspect there's some other stuff that needs set up somewhere for that to work, but I've not yet figured out what.Here's a jsfiddle with a slightly modified version of your code loading a document off my domain, works for me in Firefox and Chrome.