2012-08-11 72 views
0

我遇到了iframe高度的問題。無法控制iframe高度

在它的父頁面,我們設置它的高度= 900px,這樣的:

<html lang="en-us"> 
    <head> 
     <?php include_once "./includes/header.php"; ?> 
    </head> 
    <body> 
     <?php include_once "./includes/top.php" ?> 
     <?php include_once "./includes/left_nav.php" ?> 
     <section id="content"> 
     <iframe width="100%" height="900" id="myFrame" src="./modules/ophthalmology/patients.php" scrolling="no" frameborder="0"> 
     </iframe> 
     </section> 
     <?php include_once "./includes/footer.php" ?> 
    </body> 
    </html> 

,但它不能顯示它裏面的所有內容。我查的螢火蟲元素,然後發現:

<iframe id="myFrame" width="100%" scrolling="no" height="208" frameborder="0" src="./modules/ophthalmology/patients.php"> 

高度改爲208

但在另一個模塊,它的源代碼:

<html lang="en-us"> 
    <head> 
     <?php include_once "./includes/header.php"; ?> 
    </head> 
    <body> 
     <?php include_once "./includes/top.php" ?> 
     <?php include_once "./includes/left_nav.php" ?> 
     <section id="content"> 
     <iframe width="100%" height="900" id="myFrame" src="./modules/csvfileupload/index.html" scrolling="no" frameborder="0"> 
     </iframe> 
     </section> 
     <?php include_once "./includes/footer.php" ?> 
    </body> 
    </html>    

將其改爲:

<iframe id="myFrame" width="100%" scrolling="no" height="930" frameborder="0" src="./modules/csvfileupload/index.html"> 

這兩個唯一的區別是src文件不同,首先是patients.php,第二個是index.html。所有其他人都一樣。

我已經檢查的內容元素,它的CSS:

#content { 
     border: 1px solid; 
     border-bottom-left-radius: 4px; 
     border-bottom-right-radius: 4px; 
     margin: 0; 
     min-height: 600px; 
     overflow: visible; 
     padding: 15px 5px 15px 230px; 
    } 

而且我還發現有在的header.php一個js函數:

function sizeFrame() { 
     var F = document.getElementById("myFrame"); 
     if(F.contentDocument) { 
      F.height = F.contentDocument.documentElement.scrollHeight+30; //FF 3.0.11, Opera 9.63, and Chrome 
     } else { 
      F.height = F.contentWindow.document.body.scrollHeight+30; //IE6, IE7 and Chrome 
     } 
    } 
    window.onload=sizeFrame; 

什麼問題?

回答

0

對於嵌入iframe的HTML文檔,您的JavaScript代碼只需將0123添加到iframe元素的height屬性的值中即可。這解釋了值930.與此處的目標看起來相反,您獲得的scrollHeight值僅僅是嵌入式文檔的內嵌框架元素的高度,而不是嵌入式文檔的固有高度要求。

對於非HTML類型的嵌入式文檔,可能會發生奇怪的事情。例如,如果它是一個純文本文件,那麼scrollHeight值可能反映了內在高度要求,該要求源自其中的行數。當請求./modules/ophthalmology/patients.php時,如果不知道服務器返回的內容,我可以猜測它是非HTML的。

+0

我修復了這個問題。它是由錯誤的js代碼引起的。我刪除它,沒關係。 – PhilipSong 2012-08-11 23:17:25