ホームページ  >  記事  >  ウェブフロントエンド  >  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) {
'エラー: ' + e.number + '; ' + e.description;
}
}

iframe:

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。