日期:2014-05-16  浏览次数:20308 次

iframe 框架加上链接高度怎么随页面高度自动变长
iframe 框架加上链接高度怎么随页面高度自动变长
比如是SRC=‘http://www.hao123.com’ 可以也是以前的网址。。。怎么能自动高度的呢

------解决方案--------------------
http://www.cnblogs.com/_zjl/archive/2012/03/15/2397884.html

如果还有需要,搜索关键字“自适应 iframe”
------解决方案--------------------
HTML code

<script language="javascript" type="text/javascript">
function dyniframesize(down) {
var pTar = null;
if (document.getElementById){
pTar = document.getElementById(down);
}
else{
eval('pTar = ' + down + ';');
}
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 +20;
pTar.width = pTar.contentDocument.body.scrollWidth+20;
}
else if (pTar.Document && pTar.Document.body.scrollHeight){
//ie5+ syntax
pTar.height = pTar.Document.body.scrollHeight;
pTar.width = pTar.Document.body.scrollWidth;
}
}
}
</script>
<iframe src ="test2.html" frameborder="1" marginheight="0" marginwidth="0" frameborder="0" scrolling="auto" id="ifm" name="ifm" onload="javascript:dyniframesize('ifm');" width="100%">
</iframe>