iframe自适应内容高度的处理方法

来源:互联网 发布:iphone5s联通4g网络 编辑:程序博客网 时间:2024/05/01 12:41

在页面中

<iframe src="xx.html" marginheight="0" marginwidth="0" frameborder="0" scrolling="no" width="765" height=100% id="iframepage" name="iframepage" onLoad="iFrameHeight()" ></iframe>

添加js代码

<script type="text/javascript" language="javascript">    function iFrameHeight() {        var ifm= document.getElementById("iframepage");        var subWeb = document.frames ? document.frames["iframepage"].document :ifm.contentDocument;            if(ifm != null && subWeb != null) {            ifm.height = subWeb.body.scrollHeight;            }    }</script>


0 0
原创粉丝点击