【iframe高度自适应和宽度自适应】iframe高度自适应和宽度自适应

更新时间:2017-03-27    来源:浏览器    手机版     字体:

【www.bbyears.com--浏览器】

这是一个兼容所有浏览器的iframe自适应代码,他可以对高度与宽度进行自适应,有需要的朋友可以参考一下。
<script language="JavaScript">
/**/
//iframe高度自适应

function IFrameReSize(iframename) { 
    var pTar = document.getElementById(iframename); 
    if (pTar) {  //ff
        if (pTar.contentDocument && pTar.contentDocument.body.offsetHeight) { 
            pTar.height = pTar.contentDocument.body.offsetHeight; 
        } //ie
        else if (pTar.Document && pTar.Document.body.scrollHeight) { 
            pTar.height = pTar.Document.body.scrollHeight; 
        } 
   } 

}
//iframe宽度自适应

function IFrameReSizeWidth(iframename) { 
    var pTar = document.getElementById(iframename); 
    if (pTar) {  //ff
        if (pTar.contentDocument && pTar.contentDocument.body.offsetWidth) { 
            pTar.width = pTar.contentDocument.body.offsetWidth; 
        }  //ie
        else if (pTar.Document && pTar.Document.body.scrollWidth) { 
            pTar.width = pTar.Document.body.scrollWidth; 
        } 
   } 
}
</script>

本文来源:http://www.bbyears.com/bangongshuma/31485.html

猜你感兴趣

热门标签

更多>>

本类排行