ifame高度自动适应子页面内容

 

被这个问题折磨了好久,试了很多方法都不行,总算解决了,记录一下。

 

<div class="iframe-pro" id="iframe-proid">
    <iframe marginwidth="0" marginheight="0" hspace=0 vspace=0 frameborder="0" name="detail" frameBorder=0 scrolling=no
            src="${base}/detail/${tempId}" onLoad="iFrameHeight()"  width="920" id="detail" ></iframe>
</div>
<script type="text/javascript" language="javascript">
    function iFrameHeight() {
        var ifm = document.getElementById("detail");
        var subWeb = document.frames ? document.frames["detail"].document : ifm.contentDocument;
        if (ifm != null && subWeb != null) {
            ifm.height = subWeb.body.scrollHeight;
            $('#iframe-proid').css({height:ifm.height});
        }
    }
</script>

 

posted @ 2017-03-03 11:11  西瓜子儿  阅读(169)  评论(0编辑  收藏  举报