2012-05-24 2 views
0

iframe의 크기를 줄이거 나 늘릴 수있는 빠른 javascript 솔루션을 알고 싶습니다. 스크롤 막대가 필요 없도록 내용을 기준으로 크기가 커집니다.내용에 따라 동적으로 iframe의 크기를 조절하십시오.

프레임 소스는 사용자의 입력에 따라 변경되며, iframe에 따라 크기를 조정하고 싶습니다.

내가 가지고있는 iframe이 코드는 다음과 같습니다

<iframe id="edit_add_configuration" src="<?php echo site_url();?>"> 
     browser does not support this 
</iframe> 
+2

iframe과 외부 페이지가 같은 도메인에 있습니까? – nunespascal

+1

[Iframe의 src URL의 Iframe 콘텐츠에 따라 동적으로 Iframe 크기 조정] (http://stackoverflow.com/questions/7441443/resize-of-iframe-dynamically-depending-on-the-content) iframe-of-the-ifram) – jmort253

+0

예 해당 도메인에 있음 – user1371011

답변

2

은 높이와 너비를 가져옵니다.

var height = document.getElementById("edit_add_configuration").contentWindow.document.body.scrollHeight; 
var width = document.getElementById("edit_add_configuration").contentWindow.document.body.scrollWidth; 

iframe의 크기를 조정하십시오.

document.getElementById("edit_add_configuration").style.height=height+"px"; 
document.getElementById("edit_add_configuration").style.width=width+"px"; 
관련 문제