Reputation: 433
Trying to create a function that re-sizes iframes at window.onload
.
The following works with Fire Fox but not IE 9. After searching I tried a few of the other examples but they mess up the Fire Fox re-size and don't fix the IE 9 re-size.
Any suggestions?
<script type="text/javascript" language="javascript">
function sizeFrame() {
var frames = document.getElementsByTagName('iframe');
for (var i = 0; i < frames.length; i++){
var fID = frames[i].id;
var F = document.getElementById(fID);
if(F.contentDocument && F.contentDocument.documentElement.scrollHeight) {
F.height = F.contentDocument.documentElement.scrollHeight+30; //FF 3.0.11, Opera 9.63, and Chrome
} else if(F.contentDocument && F.contentDocument.documentElement.offsetHeight) {
F.height = F.contentDocument.documentElement.offsetHeight+30; //standards compliant syntax – ie8
} else {
F.height = F.contentWindow.document.body.scrollHeight+30; //IE6, IE7 and Chrome
}
}
}
window.onload=sizeFrame;
</script>
Upvotes: 2
Views: 1077
Reputation: 13077
I think if you just did
F.contentWindow.document.body.offsetHeight+30;
Rather than the three tests you currently have it would work much better for you.
Upvotes: 1