实现iFrame自适应高度


<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 ="/default2.aspx"  frameborder="0" marginheight="0" marginwidth="0"  frameborder="0" scrolling="auto" id="ifm" name="ifm"  onload="javascript:dyniframesize('ifm');"  width="100%">
</iframe>

posted @ 2010-05-10 20:04  go on coding  阅读(186)  评论(0编辑  收藏  举报
悠季瑜伽会馆