1

I have a lot of iframes and I want that each of the iframe would have it's height and width same as it's content.

For example : if iframe content is 1300x300, I need that iframe would be 1300x300 on my page. I am loading iframes from my domain.

לבני מלכה
  • 15,925
  • 2
  • 23
  • 47
Angulandy2
  • 786
  • 4
  • 13
  • 31

1 Answers1

-1

Try below code and check

// add in had

<script>
  function resizeIframe(obj) {
    obj.style.height = obj.contentWindow.document.body.scrollHeight + 'px';
  }
</script>

//change iframe

<iframe src="..." frameborder="0" scrolling="no" onload="resizeIframe(this)" />
PPL
  • 6,357
  • 1
  • 11
  • 30
  • I am gettint error : -LB_1v_F9EZ67x_myUKU:1 Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "http://localhost:4200" from accessing a cross-origin frame. – Angulandy2 May 03 '18 at 10:25
  • I am loading it from a .zip file in my database. – Angulandy2 May 03 '18 at 10:25
  • change script position in footer and check i think problem in you other j query conflict with script code – PPL May 03 '18 at 10:29
  • Nah, it's blocking because I can't reach iframe height if it's content in another domain – Angulandy2 May 03 '18 at 10:35