2016-07-24 6 views
0

すべてのコンテンツを読み込むiframeを持つページがあります。私は、フレームがロードされたら、iFrameの高さを設定しようとしていました。iframeの高さを設定できません

このコードは、親上で実行されて

$iFrame.load(function() { 

    this.style.height = 
     this.contentWindow.document.body.offsetHeight + 30 + 'px'; 

    console.log('onload height', this.style.height); 
}); 

コンソールが私にonload height 1229px

を与えているけれども、私はiFrameの window.document.body.offsetHeight

をロードするページでこれを実行する場合、それは1535

私に語りました

同じ値を得られないようです。スクリプトが読み込まれた後

私は両親を設定

は常にページ

に応じて、オフ500により、以上のようです、

if(inIframe()) { 
    $('iframe#page-content', window.parent.document).height($(window).height() + 'px'); 
} 

それは私に上記と同様の値を示し$(function() {})を使用してIFRAME何か案は?

+0

を多分関連:http://stackoverflow.com/questions/17845027/what-is-difference-between-width-innerwidth-and-outerwidth-height-innerheight – Toby

+0

試してみてください。 https://developer.mozilla.org/en-US/docs/Web/API/Element/clientHeight – Cryptopat

+0

のiframeの親は、本体であると私は最小の高さを持っていますが、最大の高さを設定し、何のCSSは、ありませんiframe上の1000ピクセルの値 – Ben

答えて

0

これを行います。

$iFrame.load(function() { 
    this.style.height = '100%'; 
    console.log('onload height', this.style.height); 
}); 
+0

また、親要素が1229 –

関連する問題