I have an iframe for a cross-domain site. I want to read the DOM of the iframe, which I believed was possible because using the inspector, I can even modify the DOM of an iframe. Every way I attempt to read it, however, I run into the same origin policy. All I want, is the content loaded in my local DOM, from the iframe. I thought it would be as simple as $(document.body).find('iframe').html()
, but that's returning the empty string.
I really hope there's a way to do this since the work I've been doing for the last several days has been predicated on this being do-able.
Thanks
You can't. XSS protection. Cross site contents can not be read by javascript. No major browser will allow you that. I'm sorry, but this is a design flaw, you should drop the idea.
EDIT
Note that if you have editing access to the website loaded into the iframe, you can use postMessage (also see the browser compatibility)