Simple question which I can’t seem to find an answer of:
I have two iframes on a page and I’d like to copy the content of the first one to the second.
But I can’t do it by just copying the url of the first iframe to the second since the containing page is a dynamic one.
This code does do it, but a lot of the page-formatting seems to get lost. And I don’t know if it’s cross-browser either.
iframe2.contentWindow.document.write(iframe1.contentWindow.document.body.innerHTML);
Can this be done?
Native JavaScript Solution As Asked For:
First, to make things simple I created 2 object literals:
Next, I put everything under iframe1’s
window.onloadhandler to make sure it was loaded fully:Then I assigned all of the object literal properties:
Next, I needed to create a couple functions
removeNodes()andappendNodes()so that I could re-factor some code that is used for both<head>and<body>routines.and:
With those functions created, now all we have to do is make our calls:
… and finally, we close off the
window.onloadfunction: