iframe自适应高度
使iframe自适应高度
两点注意:
1)js代码放在iframe标签下
2)相应的需要在iframe标签中展现的页面要有高度
<iframe id="iframe" name="iframe" style="border:0px;width:740px;height:415px;" src="<?php echo site_url('index/home/index_main')?>"
frameborder="0" width="100%" scrolling="no" height="100%"></iframe>
<script type="text/javascript">
//注意:下面的代码是放在和iframe同一个页面调用,放在iframe下面
$("#iframe").load(function () {
var mainheight = $(this).contents().find("body").height() + 30;
$(this).height(mainheight);
});
</script>