2

Below is my code which I am using to load iframe content with dynamic height of the iframe content:

<iframe id="form-iframe" 
        style="margin: 0; width: 100%; height: 100%; border: none; overflow: hidden;" 
        src="URL" width="300" height="150" scrolling="no" 
        onload="AdjustIframeHeightOnLoad()">
</iframe>

function AdjustIframeHeightOnLoad() { 
     document.getElementById("form-iframe").style.height = \
          document.getElementById("form-iframe").contentWindow.document.body.scrollHeight 
          + "px"; 
}

But by using above code in html I am getting below error in console log

Error: Permission denied to access property "document"

How can I read the height from the content of my iframe to set my iframe-container to the same size?

tjati
  • 5,761
  • 4
  • 41
  • 56
  • Is the iframe src on the same domain? If not you may have problems. The comments in this accepted answer seem to link to a cross domain solution: http://stackoverflow.com/questions/9162933/make-iframe-height-dynamic-based-on-content-inside-jquery-javascript – Pete Jul 22 '15 at 08:39
  • check this one http://stackoverflow.com/questions/22481340/error-permission-denied-to-access-property-document – Matteo Rubini Jul 22 '15 at 08:54
  • Thank you for your response. And yes in src which i use is different domain url. But in javascript if i used " contentWindow.document.body.scrollHeight " i am getting that error. Do we have any other method to set height of the iframe dynamically. Can you please help with any example. – Php Developer Jul 22 '15 at 08:57
  • Is there any possibility to load iframe automatically after clicking anything inside iframe where it has to load height automatically depending upon content in iframe. – Php Developer Jul 24 '15 at 14:15

0 Answers0