2016-08-15 11 views
0

iFrame内のコンテンツのサイズに基づいてiFrameのサイズを変更しようとしていますが、ユーザーがiFrame内をクリックして状態を確認するときに問題が発生します。私は、ユーザーがiFrameのが600PXに設定されますが、ユーザーがなったときにされ、コンテンツが600PXあるページになると、結構ですのでjQueryのチェックiFrameの高さと調整

var checkHeight = setInterval(function(){ 
checkHeight(); 
},1000); 

function checkHeight() { 
    var height = $('.foo').contents().height(); 
    console.log(height) 
    $('.foo').css({ 
    'height': height + 'px' 
    }); 
} 

などのコンテンツのサイズをチェックする間隔を使用してのiFrame高さが200px、iFrameがログアウトして600pxに設定されたページに、jQueryが最高の高さの数字を保存している理由を理解できませんか?各関数呼び出しで値をゼロに設定すると、ページがバウンスします。

答えて

0

私はそのような何か使用しています:

$(function(){ 
    $('#foo').load(function(){ 
     $('#foo').contents().find("body").on('click', function(event) { 
      runAfterTimeout('foo'); 
     }); 
    }); 
}); 

function runAfterTimeout(id) { 
    setTimeout(function(){ 
     autoResize(id); 
    },1000); 
}; 

function autoResize(id){ 
    var newheight; 
    var newwidth; 

    if(document.getElementById){ 
     newheight=document.getElementById(id).contentWindow.document.body.scrollHeight; 
     newwidth=document.getElementById(id).contentWindow.document.body.scrollWidth; 
    } 

    document.getElementById(id).height=(newheight) + "px"; 
    document.getElementById(id).width=(newwidth) + "px"; 
} 

とiframeにこれを追加します。のonload = "AUTORESIZE( 'FOO')"

関連する問題