0

Possible Duplication of Question

This similar question has been raised many times, however those solutions do not work for me. In addition, some of the solutions stated as answers are quite similar to my example. Therefore, it should work. But, that is not the case.

Main Example tried:

 <iframe src="example.html" id="preview" ></iframe>

JavaScript:

     $(document).ready(function () {
        var previewObject = document.getElementById('preview');
        var iframeChrome = previewObject.contentDocument.documentElement; 
        var iframeOther = previewObject.contentWindow.document.body;  

        var height = Math.max(iframeChrome.scrollHeight, iframeOther.scrollHeight);
        previewObject.height = height;
     });

Additional detail:

The iframe contains a preview of a website in the same domain/directory, the iframe should not contain a scrollbar, but display the whole website in it's full height.

RH7
  • 223
  • 1
  • 11
  • Try `previewObject.style.height = height+"px";` – CBroe Nov 28 '16 at 21:04
  • Sorry `previewObject.style.height = height+"px";` doesn't work. The height assigned to the variables is always the same and never changes. – RH7 Nov 28 '16 at 21:06
  • Possible duplicate of [Adjust width height of iframe to fit with content in it](http://stackoverflow.com/questions/819416/adjust-width-height-of-iframe-to-fit-with-content-in-it) – luke Nov 28 '16 at 21:47
  • Tried and test. Both are quite similar, therefore, technically my example should work. But that is not the case – RH7 Nov 28 '16 at 21:50

0 Answers0