您的位置:首页 > 其它

iframe自适应高度

2016-12-07 15:42 411 查看
function setIFrameHeight(iframe){

           var ifm_content = document.getElementById("conFrame");

           ifm_content.height = "500px";//默认设置为500px

           var heightContent = "500px";

           var subContent = document.frames ?document.frames["conFrame"].document : ifm_content.contentDocument;

           if (iframe == "content") { //如果传入Ifame Id 等于content 重新给iframe赋值高度

                heightContent =Math.max(subContent.body.scrollHeight, subContent.documentElement.scrollHeight);

                ifm_content.height =heightContent;

           }

       }

实例说明:

我的Html中有一个Iframe 用法如下:

<iframeid="conFrame"
src="a.html"
frameborder="0"scrolling="no"
            width="100%"height="500px"
onload="setIFrameHeight('content');"></iframe>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  iframe 自适应高度