ページのコンテンツに合わせて iFrame の高さを動的にしようとしています。
2ページあります。index.php と example.html
「index.php」に「example.html」をiFrameとして挿入すると、「example.html」のコンテンツの高さが変更可能になります。
これは「index.php」の私のコードです
<iframe src="example.html" name="iframe1" id="myiframe" marginwidth="0"
marginheight="0" align="top" scrolling="no" width="100%" height="auto" frameborder="0">
</iframe>
<script type="text/javascript">
var f = document.getElementById("myiframe");
f.onload = function() {
this.style.height = this.contentWindow.document.body.offsetHeight + "40px";
}
</script>
私のCSS:
#myiframe {
margin: auto;
padding: 0px;
float: left;
height: auto;
min-height: 255px;
height: auto !important; /* for IE as it does not support min-height */
height: 255px; /* for IE as it does not support min-height */
width: 100%;
}
iFrame は正常に機能しますが、動的な高さはまったく機能しません。助言がありますか?ありがとう。