2012-08-27 55 views
0

我有一個DIV中的IFrame,其SRC屬性由JS函數動態設置。因此,如果src =「file.jsp」,那麼包含對file.jsp中某些樣式的調整的onload函數(在file.jsp中的body內部)會在觸發功能完成後將IFrame整個頁面懸停在整個網頁上通過onload。即,iframe正在整個網頁上傳播。請讓我知道在onload函數後需要做些什麼來保留IFrame的位置。onrame爲jsp內IFrame設置iframe到整個頁面/瀏覽器

的代碼我的onload函數如圖

function load() { 
    var url = window.location.href; 
    if (url.indexOf('iip') > -1) { 
     document.getElementById('peLibraryTreeDiv').style.width = "596px"; 
     parent.document.getElementById('privateEquityDiv').style.width = 
       "96.9%"; 
     parent.document.getElementById('privateEquityDiv').style.top = 
       "77px"; 
    } 
} 
+0

請問您可以更改,因爲它不清楚你想要實現什麼...... – MaVRoSCy

+0

我的意思是在file.jsp的onload()方法中添加任何類型的內容(這會出現在DIV中的Iframe中)導致iframe本身完全在瀏覽器中顯示。 – user993195

+0

你可以顯示onload函數和你的div的html代碼和你的div的CSS? – MaVRoSCy

回答

0

,這是一個完全有效的工作示例

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
    <head> 
     <script> 
     function changeIframe(newLocation){ 
      document.getElementById("myIframe").src=newLocation; 
     } 
     </script> 
    </head> 
    <body onload="changeIframe('http://www.example.com')"> 
     <div style="width:650px;float:auto;border:1px dotted #cccccc;"> 
      <iframe id="myIframe" src="http://www.ebay.co.uk/" width="100%" height=750px marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=1 scrolling=auto> 
       <p>Your browser does not support iframes.</p> 
      </iframe> 
     </div> 
    </body> 
</html> 

請注意,某些網站不能被添加爲SRC的iframe像http://www.google.com (不知道爲什麼,我在這裏提出了一個問題,這裏can't add google.com as src to an IFrame