0
這裏的交易...我有一個externaly加載的iframe叫「radioiframe」,我有一個本地iframe與我的網頁內容。正如你會注意到我的「radioiframe」中的src是空的,這是因爲源代碼是通過JavaScript加載的(代碼在結尾處)。所有的作品都非常完美,但我遇到的問題是當我在iframe上顯示內容並將內容向下推,隱藏它(溢出:隱藏在主體中以防止滾動條滾動)。我一直在試圖將其計算出來,「radioiframe」的高度固定爲34px,但「content」高度與顯示器大小和頁面內容有關。我試圖用jQuery計算框架的高度,然後減去高度ou 34並將其設置在iframe上,但無濟於事。 只是爲了提醒一切正在運行setSizes數學函數。身高百分比數學javascript爲iframe
框架頁面上的HTML。
<div id="radiodiv">
<iframe src="" id="radioiframe" height="34px" width="100%" marginwidth="0" marginheight="0" frameborder="0" vspace="0" hspace="0" scrolling="no" allowtransparency="true" style="display:none;"></iframe></div>
<div id="contentdiv">
<iframe src="home2.php" id="content" name="content" height="100%" width="100%" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" vspace="0" hspace="0"></iframe></div>
<script type="text/javascript">
function setSizes() {
var containerHeight = $("#content").height();
document.getElementById('content').height = containerHeight - 34;
}
</script>
的JavaScript加載來源:
function ShowSaburi(){
parent.document.getElementById('radioiframe').src = 'http://www.saburimusic.com/player.php';
parent.document.getElementById('radioiframe').style.display = 'block';
};
function ShowNero(){
parent.document.getElementById('radioiframe').src = 'http://www.radionero.com/player.php';
parent.document.getElementById('radioiframe').style.display = 'block';
};
function HideRadio(){
parent.document.getElementById('radioiframe').src = '';
parent.document.getElementById('radioiframe').style.display = 'none';
};
不能工作,因爲div不能獲得框架頁面的高度,但它獲得了父頁面的高度 –
我使用了一些代碼,只是稍微調整了一下它,但有任何想法在Chrome中它削減了一點底部?在IE和Firefox中是完美的。 –
$(文件)。就緒(函數autoHeight(){ \t變種docHeight = $(文件).height(); \t變種radioHeight =父$( 「#radioiframe」)高度(); \t如果( docHeight)var contentHeight = docHeight - radioHeight; parent。$('#content')。css({'height':contentHeight +'px'}); } }); –