2013-10-19 142 views
1

我無法根據頁面內容調整自動高度。使iframe自動調整高度

碼 -

<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?但是這個代碼不工作。請建議我如何在不使用滾動的情況下獲取完整數據?

+0

請參閱此。類似的一個http://stackoverflow.com/questions/9162933/make-iframe-height-dynamic-based-on-content-inside-jquery-javascript – chandu

+0

@chandu是的,它爲同一個域的工作。它將如何工作跨域? – Developer

回答

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> 
+0

不工作。 無法在主體中找到函數autoResize() – Developer