2011-08-18 94 views
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'; 
}; 

回答

0

怎么样和溢出设置造型contentdiv滚动

<div id="contentdiv" style="overflow: scroll;"> 
    <iframe src="home2.php" id="content" name="content" height="200px" width="100%" frameborder="0" scrolling="auto" marginwidth="0" marginheight="0" vspace="0" hspace="0"></iframe> 
</div> 

可以在div的高度设置为窗口的最大高度radioiframe的34px以下。

希望这会有所帮助。

function ShowSaburi() { 
// your methods 
// add this 
setContentHeight(); 
} 

function setContentHeight() { 
    var docHeight = $(document).height(); 
    if (docHeight){ 
     var contentHeight = docHeight - 40; 
     $('#contentdiv').css({'height': contentHeight+ 'px'}); 
    } 
} 

只是一个想法。

+0

不能工作,因为div不能获得框架页面的高度,但它获得了父页面的高度 –

+0

我使用了一些代码,只是稍微调整了一下它,但有任何想法在Chrome中它削减了一点底部?在IE和Firefox中是完美的。 –

+0

$(文件)。就绪(函数autoHeight(){ \t变种docHeight = $(文件).height(); \t变种radioHeight =父$( “#radioiframe”)高度(); \t如果( docHeight)var contentHeight = docHeight - radioHeight; parent。$('#content')。css({'height':contentHeight +'px'}); } }); –