MDN self-hosted library · e01.org

Window: requestResize() method

Runnable notebook: every JavaScript, HTML and CSS example on this page executes in a sandboxed local frame. Nothing leaves the browser.

html
<h1>Responsive iframes — basic example</h1>

<iframe src="frame.html"></iframe>
css
iframe {
  frame-sizing: content-block-size;
  border: 2px solid gray;
}
html
<head>
  <!-- ... -->

  <meta name="responsive-embedded-sizing" />

  <!-- ... -->
</head>
<body>
  <div tabindex="0">
    <h1>This is my frame</h1>
    <p>This is the content of my discontent.</p>
    <p>This is some more content.</p>
  </div>
  <script>
    /* ... */
  </script>
</body>
js
const divElem = document.querySelector("div");
divElem.addEventListener("click", addParagraph);
window.addEventListener("keydown", addParagraph);
js
function addParagraph() {
  const para = document.createElement("p");
  para.textContent = "New content.";
  divElem.appendChild(para);
  window.requestResize();
}