Search code examples
javascriptiframeiframe-resizer

iframe-resizer not resize iframe with srcdoc html


I want to resize an the height of an iframe using html from srcdoc and I choosed to use the iframe-resizer library. But the iframe is never resizing and callbacks are never called.

Html :

<iframe scrolling="no" class="preview-iframe" id="iframe3" srcdoc="<html><head></head><body><p>TEST</p>
</body></html>"></iframe>

JS :

$('iframe#iframe3').iFrameResize({
  heightCalculationMethod: 'bodyScroll',
  log: true,
  resizedCallback: function () {
    console.log('resize');
  },
  initCallback: function () {
    console.log('init');
  },
});

Here is my jsfiddle


Solution

  • You srcdoc needs to have a link to the iframeResizer.contentWindow.js file in it.