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
本站声明:网站内容来源于网络,如有侵权,请联系我们,我们将及时处理。
还没有人抢沙发呢~