I have an iframe that I populate the src of at runtime:
$(iframe).attr("src", "<my html page uri>");
Followed by:
$(iframe).load(function() {
//Copy style from parent
if (setStyles) {
setStyles = false;
var linkTags = window.parent.document.head.getElementsByTagName("link");
for (var i = 0; i < linkTags.length; i++) {
if (linkTags[i].rel === "stylesheet") {
var node = linkTags[i].cloneNode();
node.href = linkTags[i].href;
this.contentDocument.head.appendChild(node);
}
}
}
//add some elements dynamically
var windowHeight = iframe.contentWindow.document.body.scrollHeight;
$(iframe).height(windowHeight + 'px');
});
The second last 2 lines of code are there to resize the frame to fit its content after I appended some elements.
This works, but the problem is the CSS that I dynamically added resizes some of the elements, and that means the frame is the wrong height again.
Do I need to chain the dynamic CSS addition and the resizing of the frame so that the CSS is applied to the elements before the re-size happens?
If so, how? Thanks