首页 > 其他 > 详细

iframe 标签自适应高度和宽度

时间:2015-11-17 10:57:49      阅读:292      评论:0      收藏: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);
}); 

 

iframe 标签自适应高度和宽度

原文:http://www.cnblogs.com/rsky/p/4970834.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!