实测iframe自适应高度的两种方法
方案一
<iframe name="myiframe" id="myiframe" src="#" frameborder="0" scrolling="no"></iframe>
<script type="text/javascript" language="javascript"> $(window.parent.document).find("#myiframe").load(function(){ var main = $(window.parent.document).find("#myiframe"); var thisheight = $(document).height()+30; main.height(thisheight); }); </script>方案二
拖拽窗口iframe也可以自适应高度
<iframe name="myiframe" id="myiframe" src="#" frameborder="0" scrolling="no"></iframe>
<script type="text/javascript" language="javascript"> function changeFrameHeight(){ var ifm= document.getElementById("myiframe"); ifm.height=document.documentElement.clientHeight-56; } window.onresize=function(){ changeFrameHeight();} $(function(){changeFrameHeight();}); </script>