rsky

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);
}); 

 

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-02-07
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-22
  • 2021-07-28
  • 2021-06-12
  • 2022-12-23
相关资源
相似解决方案