public
Created

BLOG: adoptNode()

  • Download Gist
adoptnode.js
JavaScript
1 2 3 4 5 6 7
try {
document.adoptNode(window.opener.$("#my-iframe"))
}
catch(exc) {
// performance hit. Either importNode, or load the frame contents with appendChild()
document.importNode(window.opener.$("#my-iframe"))
}
css-workaround.html
HTML
1 2 3 4 5
<div id="#placeholder"></div>
 
<!-- ...last node in the page... -->
<iframe id="theFrame" src="http://www.example.com" style="left: -12345px; top: 0; position: absolute;"></iframe>
</body>
css-workaround.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
(function() {
var div = document.getElementById("placeholder");
var iframe = document.getElementById("theFrame");
 
window.setInterval(function putFrameOntoPlaceholder() {
// 1) measure the size of the iframe, change size of div
div.width = iframe.offsetWidth + "px";
div.height = iframe.offsetHeight + "px";
 
// 2) get the div's position on the page, position iframe
iframe.left = div.offsetLeft + "px";
iframe.top = div.offsetHeight + "px";
}, 100);
 
})();

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.