时间: 2020-11-23|65次围观|0 条评论

iframe 结构如下

<iframe src="index.html" id="frame" frameborder="0" scrolling="no" marginheight="0" marginwidth="0" onLoad="iFrameHeight()"></iframe>

 

js 实现

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

 

jQuery 实现

$("#frame").load(function(){
    var mainheight = $(this).contents().find("body").height()+30;
    $(this).height(mainheight);
}); 

 

转载于:https://www.cnblogs.com/rsky/p/4970834.html

原文链接:https://blog.csdn.net/weixin_30342827/article/details/95089010

本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。

本博客所有文章如无特别注明均为原创。
复制或转载请以超链接形式注明转自起风了,原文地址《iframe 标签自适应高度和宽度
   

还没有人抢沙发呢~