2014-09-30 4 views
0

내 iframe의 높이를 콘텐츠에 맞게 자동 조정하고 싶습니다. 나는 jQuery 플러그인 jquery-iframe-auto-height를 house9로 작성했다. 실제로 잘 작동한다.iFrame의 높이를 jQuery로 조정하십시오.

이제 홈페이지 (iframe)에 상위 페이지의 전체 높이가 있어야합니다. 나는 if else 문을 사용해야한다고 생각했지만 자바 스크립트 (아직)에 익숙하지 않았기 때문에 여러분 중 한 명이 나를 도울 수 있기를 바랍니다.

$(document).ready(function() { 
    if ((#ifrm).($this).attr('src') == 'home.html'){ 
     $('#ifrm').iframeAutoHeight({minHeight: 100%}); 
    } 
    else $('#ifrm').iframeAutoHeight({minHeight: 300}); 
}); 

또한 나는 어쩌면
if ($('#ifrm').($this).attr('src') == 'home.html'){ 
    (function(){var height = $(window).height(); 
     $('#ifrm').css('height', height) 
    }); 
    } 
    else $('#ifrm').iframeAutoHeight({minHeight: 300, debug: true}); 

가 사전에 너무 감사하는 데 도움이 페이지의 전체 높이를 점점이 하나 개의 코드를 발견

편집 : 당신이 웹 사이트를 찾을 수있는이 이 코드는 당신을 위해 일한다 here

+0

'if ($ ('# ifrm '). attr ('src ') =='home.html ') {' – andrew

답변

0

에 대한되었습니다

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> 

<script> 
    $(document).ready(function() { 
     if ($('#ifrm').attr('src') == 'home.html') { 
      var window_height = $(window).height(); 
      $('#ifrm').css("height", window_height); 
     }else{ 
      $('#ifrm').load(function() { 
       this.style.height = 
       this.contentWindow.document.body.offsetHeight + 'px'; 
      }); 
     } 
    }); 
</script> 

<iframe src="home.html" id="ifrm"> 

그것은뿐만 아니라 자동 플러그인 (항상 바람직), 또한이 것을 염두에두고 "home.html을"페이지

곰의 전체 높이를 설정을 사용하지 않고 내용에 iframe 대응의 높이를 조정 iframe 내용이 동일한 도메인에있는 경우에만 작동하며 다른 도메인의 iframe 내용은 보안을 위해 잠겨 있습니다.

+0

정말 고마워요! 어떤 사이트인지 확인하고 싶다면, [여기 링크가 있습니다] (http://g9995.hageveld2.nl/Niels/ww/). 이것은 내가이 사이트를 끝내기 전에해야 할 큰 일이었습니다. 그래서 이것은 큰 도움이됩니다. :) –

관련 문제