首页 文章

使iframe自动调整高度

提问于
浏览
1

我无法根据页面内容调整自动高度 .

代码 -

<iframe width="100%" id="myFrame" src="http://www.learnphp.in" scrolling="no">
</iframe>

我更喜欢Make iframe automatically adjust height according to the contents without using scrollbar?但这段代码不起作用 . 请建议我如何在不使用滚动的情况下获取完整数据?

1 回答

  • 0

    试试这个

    <script>   
    function autoResize(myiframe){
        var newheight;
        var newwidth;
    
        if(document.getElementById){
            newheight=document.getElementById(id).contentWindow.document .body.scrollHeight;
            newwidth=document.getElementById(id).contentWindow.document .body.scrollWidth;
        }
    
        document.getElementById(myiframe).height= (newheight) + "px";
        document.getElementById(myiframe).width= (newwidth) + "px";
    }
    </script>
    
    <body>  
     <div align="center" style="padding-left:50px">
          <iframe id="myiframe" src="helpdesk/index.php" width="800"></iframe>
     </div>
    </body>
    

相关问题