2015-07-05 128 views

回答

-1

您無法獲取底框文檔高度,因此無法制作動態更改iframe高度...
您只需添加滾動條即可。

+0

我可以看到@Anamika想要做的是改變iFrame尺寸,而不是它的內容(src)這是可能的:) – Ali

+0

我可以看動態單詞。 –

+0

這意味着不是靜態的(總是相同的),它可以是動態的,並根據其src和不同的URL進行更改:) – Ali

1

您可以通過爲iframe加載時添加事件處理程序來完成此操作。在此功能中,得到的iframe的src,並使用switch聲明應用基於其不同的風格:

開始通過給你的iframe的ID(如果尚未完成):

<iframe id="myFrame"></iframe> 

和JS可以聽:

document.getElementById('myFrame').onload= function() { 
    switch(this.src){ 
    case 'http://example.com/index' : // Will fall through and execute same code as below 
    case 'http://example.com/'  : this.style.width = '400px'; 
             this.style.height = '200px'; 
             break; // Stop switch 
    case 'http://example.com/about' : this.style.width = '700px'; 
             this.style.height = '500px'; 
             break; 
    default : /* Do something or not */ 
    } 
};