您的位置:首页 > 其它

iframe自动适应内容的高度

2009-10-26 13:56 405 查看
方法一:

<script>
function autoResize()
{
try
{
document.all["mainFrame"].style.height=mainFrame.document.body.scrollHeight
}
catch(e){}
}
</script>
<iframe name="mainFrame" src="/ads/?ad=google&ad2=biz2008" marginwidth="0" marginheight="0" frameborder="0" scrolling="no" width="100%" style="height:expression(1); aho:expression(autoResize())"></iframe>

方法二:

<iframe src="comment.jsp" id="mainFrame" name="mainFrame" style="margin:20px 0;width:95%;height:600px;" border="0" frameborder="0" marginwidth="0" marginheight="0" allowtransparency="yes" ></iframe>

<script>
function iframeResize()
{
var dyniframe = document.getElementById("mainFrame");

if (dyniframe) {
if (dyniframe.contentDocument)
{
dyniframe.style.height = dyniframe.contentDocument.body.scrollHeight + 10;
}
else if (dyniframe.document && dyniframe.document.body.scrollHeight)
{
iframeheight = mainFrame.document.body.scrollHeight + 10;
dyniframe.style.height = iframeheight;
}
}
}

function scroll_to_top()
{
document.body.scrollTop=0;
}

if (window.addEventListener)
window.addEventListener("load", iframeResize, false);
else if (window.attachEvent)
window.attachEvent("onload", iframeResize);
else
window.onload = iframeResize;
</script>

网页在最上面:

<script language="javascript">if(self!=top){top.location=self.location;};self.moveTo(0,0);self.resizeTo(screen.availWidth,screen.availHeight); </script>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: