문제

콘텐츠에 따라 iframe의 높이를 자동으로 크게 만드는 JavaScript 스크립트를 작성했습니다. 이것은 프레임 페이지의 내용이 생성되는 즉시 수행됩니다. Firefox에서는 문제가 없지만 즉, 스크립트는 올바르게 실행되지만 효과는 보이지 않습니다. 메소드는 콜백 함수에서 호출됩니다. uggesions? 버튼을 사용하여 메소드를 실행하면 완벽하게 작동하며 프레임이 조정됩니다.

나는 내 앞에서 코드가 없었다. 크기 조정 방법은 다음과 같습니다.

function resizeFrame(){
    var frame = parent.document.getElementsById(window.me);
    frame.style.height = document.offsetHeight;
}

그리고 호출 함수는 다음과 같습니다.

//init function
bunding.doSomeWork(callbackFunction);
...

function callbackFunction()
{
    //does some HTML output
    resizeFrame();
}

Salesforce Ajax 라이브러리를 사용하고 있습니다.

도움이 되었습니까?

해결책

일부 경우 IE 속성에서 오프 스테이트, 클라이언트 및 ScrollHeight와 같은 새 컨텐츠가 추가되었을 때 올바르게 설정되지 않음을 발견했습니다. 그러한 속성에서 정확한 값을 얻기 전에 디스플레이를 다시 칠할 수 있도록 Settimeout을 사용해야했습니다.

다른 팁

코드를 보지 않고 실제로 디버깅하기는 어렵지만 IE와 Firefox에서 다음 예제가 잘 작동합니다.

<!DOCTYPE html>
<html>
<head>
  <title>so-iframeResize</title>
  <script type="text/javascript" >

    onframeload=function(iframe) {
      var doc = iframe.contentWindow.document;
      iframe.style.height = Math.max(
        doc.getElementsByTagName("html")[0].offsetHeight,
        doc.body.offsetHeight // IE prefers this value
      ) + "px";
    };

  </script>
</head>
<body>
  <div id="page">
    <iframe src="about:blank" onload="onframeload(this)">
    </iframe>
  </div>
</body>
</html>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top