牛骨文教育服务平台(让学习变的简单)
博文笔记

iframe 根据内容自适应高度-终极解决方案

创建时间:2016-07-05 投稿人: 浏览次数:31444

第一中方法:

在子页面加载完毕的时候执行

parent.document.getElementById("iframe").height=0;

parent.document.getElementById("iframe").height=document.body.scrollHeight;


第二中方法:

在主页面 iframe onLoad 时间里面写

function iframeLoad()
{
    document.getElementById("iframe").height=0;
    document.getElementById("iframe").height=document.getElementById("iframe").contentWindow.document.body.scrollHeight;
}



推荐第二种

声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。