Iframeページの高さを取得するjavascript
1891 ワード
<iframe id="contentframe" src="@ViewBag.Url" height="1000px" frameborder="0" width="100%" allowtransparency scrolling="no">
</iframe>
<script type="text/javascript">
$(function () {
try {
var frame = document.getElementById("contentframe");
frame.onreadystatechange = function () {
if (this.readyState == "complete")
var ifm = document.getElementById("contentframe");
var subWeb = document.frames ? document.frames["contentframe"].document : ifm.contentDocument;
if (ifm != null && subWeb != null) {
ifm.height = subWeb.body.scrollHeight;
}
}
}
catch (err) {
$("#contentframe").attr("height", 1000);
}
})
</script>