首頁  >  文章  >  web前端  >  iframe自动适应高度1_html/css_WEB-ITnose

iframe自动适应高度1_html/css_WEB-ITnose

WBOY
WBOY原創
2016-06-24 12:03:13889瀏覽

js:

function iFrameHeight() { 
var ifm= document.getElementById("iframepage"); 
var subWeb = document.frames ? document.frames["iframepage"].document : ifm.contentDocument;
if(ifm != null && subWeb != null) { 
ifm.height = subWeb.body.scrollHeight; 

}

iframe:

 

下面的兼容性比较好:
/*兼容FF/IE9/IE8/IE7/IE6*/
function iframeResize(iframe) {
        try {
            //var iframe = document.getElementById("contentFrame"); //("contentFrame");
            var idocumentElement = iframe.contentWindow.document.documentElement;
            if (idocumentElement.scrollHeight > 560) {
                iframe.height -= 5;
                iframe.height = idocumentElement.scrollHeight;
            }
            else {
                iframe.height = 560;
            }
        }
        catch (e) {
            window.status = 'Error: ' + e.number + '; ' + e.description;
        }
    }

 

iframe:

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn