一、IFRAME自适应高度,可以考虑广告显示的js和ppc按钮显示的js应用
<iframe src="/Down_AD.aspx" _fcksavedurl=""/Down_AD.aspx"" _fcksavedurl=""/Down_AD.aspx"" name="iframe" id="iframe" allowtransparency="true" align="default" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" height="200" width="500" onload="this.height=0;var fdh=(this.Document?this.Document.body.scrollHeight:this.contentDocument.body.offsetHeight);this.height=(fdh>200?fdh:200)"></iframe>
二、 <script>
function dyniframesize(iframename)
{
var pTar = null;
if (document.getElementById)
{
pTar = document.getElementById(iframename);
}
else{
eval('pTar = ' + iframename + ';');
}
if (pTar && !window.opera){
//begin resizing iframe
pTar.style.display="block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
//ns6 syntax
pTar.height = pTar.contentDocument.body.offsetHeight+10;
}
else if (pTar.Document && pTar.Document.body.scrollHeight){
//ie5+ syntax
pTar.width = pTar.Document.body.scrollWidth;
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
</script>
function dyniframesize(iframename)
{
var pTar = null;
if (document.getElementById)
{
pTar = document.getElementById(iframename);
}
else{
eval('pTar = ' + iframename + ';');
}
if (pTar && !window.opera){
//begin resizing iframe
pTar.style.display="block"
if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight){
//ns6 syntax
pTar.height = pTar.contentDocument.body.offsetHeight+10;
}
else if (pTar.Document && pTar.Document.body.scrollHeight){
//ie5+ syntax
pTar.width = pTar.Document.body.scrollWidth;
pTar.height = pTar.Document.body.scrollHeight;
}
}
}
</script>
本文介绍了一种实现IFRAME元素自适应高度的方法,包括适用于不同浏览器环境的JavaScript代码。通过监听IFRAME加载完成事件并动态调整其高度,确保了内容能够完全展示而不会出现滚动条。

3万+

被折叠的 条评论
为什么被折叠?



