Skip to content

Instantly share code, notes, and snippets.

@inwardmovement
Last active May 5, 2025 07:08
Show Gist options
  • Save inwardmovement/1c6f3441e29d1ed790c9997e00d79ca0 to your computer and use it in GitHub Desktop.
Save inwardmovement/1c6f3441e29d1ed790c9997e00d79ca0 to your computer and use it in GitHub Desktop.

L'application intégrée en iframe doit intégrer ce script sendIframeHeight.js :

function sendIframeHeight() {
  const height = document.body.scrollHeight;
  window.parent.postMessage(
    { type: 'iframeHeight', height: height },
    '*'
  );
}

// Envoie la hauteur au chargement
window.addEventListener('load', sendIframeHeight);

// Envoie la hauteur si le contenu change
const observer = new MutationObserver(sendIframeHeight);
observer.observe(document.body, { childList: true, subtree: true });

Dans la page intégrant l'iframe :

<iframe class="iframeResize" style="border: none; width: 100%; height: 100vh" src="..."></iframe>
<script>
  window.addEventListener('message', function(event) {
    if (event.data.type === 'iframeHeight') {
      const iframeResize = document.querySelectorAll('.iframeResize');
      iframeResize.forEach(iframe => {
        iframe.style.height = event.data.height + 'px';
      });
    }
  });
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment