Copy html content from iframe to div (ajax)?
Suppose I have my iframe loaded with <iframe src="test.html">
Can I use ajax to load the contents of test.html into a div on the html main page?
This idea is my solution for this fact that I am actually trying to overcome the limitation by making ajax send remote hosts. The plan is to generate a dynamic page with an iframe of size 0, which makes a report request to the remote host. Then, after loading the page (& iframe content), I copy the contents of the iframe to the div using JS.
Tips are welcome
Thank you, Maxim.
No, you canβt.
When you load a page from another domain into an iframe, it becomes inaccessible. You can no longer access iframe content because it comes from a different domain.
The only thing I know about what you can reliably download from another domain is the script that JSONP uses.
Can I use ajax to load the contents of test.html into a div on the html main page?
Yes (since your example has a relative URI and is on the same host) ...
This idea is my solution for this fact that I am actually trying to overcome the limitation by making ajax for remote hosts.
... and no. You still cannot read data from remote hosts.
I am sure that someone will correct me if I am mistaken, but I believe that scripts across domain boundaries are limited. Have you tried this? Here's a feature that might help.
function insertDivFromFrame(divname, framename) { var frame = document.getElementById(framename); var d = frame.contentWindow || frame.contentDocument; if (oDoc.document) {d = d.document;} document.getElementById('yourdiv').innerHTML = d.body.innerHTML; } I'm not sure if this code works ... see http://xkr.us/articles/dom/iframe-document/ for more information about this.
... you can, however, design an AJAX request to a local host and get information from a remote server (as described here ).
If you write php / perl / etc. script to output the contents of the document from another domain, it will give you access to the contents, since the resulting page will be considered by javascript for your domain. If you are unfamiliar with any server-side scripting, I'm sure you can find a script that does this for you by doing a simple google search.
Good luck.