实现iFrame自适应高度,原来很简单!
<iframe id="aspx" name="aspx" width="100%"
onload="this.height=aspx.document.body.scrollHeight"
frameborder="0" src="index.htm"></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>