question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Width downsizing not working

See original GitHub issue

How do you prevent the iframe from growing unbounded? It seems easy to cause this problem, especially with width but also with height. Below is a simple minimal example - pressing ‘go’ toggles on/off a div appearing far to the right, but once it appears, the width never reverts back to its original size.

I think this is because of the following feedback loop:

  • divs are width:100% of the parent document body whose width is 100% of the iframe.
  • iFrameResizer makes the iframe width in turn determined by the document contents.

I’m hoping there’s a way to match the behavior in a normal iframe or viewport, where there’s a “viewport size” that the document body width reverts to once it’s no longer propped wider by the .c div. (Of course, without actually clipping the content to that “viewport size.”) Am I making sense? Is there a way to accomplish this?

index.html:

<script src="iframeResizer.min.js"></script>
<iframe src="child.html" scrolling="no"></iframe>
<script>
  iFrameResize({ sizeWidth: true }, document.querySelector("iframe"));
</script>

child.html:

<!DOCTYPE html>
<html>
  <body>
    <script src="iframeResizer.contentWindow.min.js"></script>
    <script>
      function go() {
        if (document.querySelector(".c").style.display === "block") {
          document.querySelector(".c").style.display = "none";
        } else {
          document.querySelector(".c").style.display = "block";
        }
      }
    </script>
    <button onclick="go()">go</button>
    <div
      class="c"
      style="height: 50px; width:10px; left: 500px; position: absolute; display: none; background: black;"
    >
      hello
    </div>
    <div style="height: 500px; width:100%; background: silver;">hello</div>
  </body>
</html>

(I’d be happy to move this into a jsfiddle or codepen, but I wasn’t sure how to get iframes to work in them.)

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:1
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
tkawai21commented, Jan 13, 2020

I just had this same issue with the iframe height not downsizing, and it turned out to be CSS on the child content. The body element had height: 100% applied to it. Once I set that to auto, the downsizing worked.

1reaction
BobSteincommented, Aug 20, 2019

Thank you for iframe-resizer. It was dreamy how well it worked on the first try.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Trouble downsizing local image to fit div - html - Stack Overflow
If the image is smaller than the containing div, no problem, it stretches to fit the div. However, when it's larger than the...
Read more >
Iframe downsizing not working - Metabase Discussion
I am working on resizing an iframe height by using Iframe resizer as mentioned here: https://www.metabase.com/docs/latest/administration-guide/13-embedding.
Read more >
How to Resize an Image Correctly | The TechSmith Blog
Open your screenshot or image in the Snagit Editor, select “Image” from the top menu, then “Resize Image.” Before changing the dimensions, notice...
Read more >
ARM CoreLink NIC-400 Network Interconnect Technical ...
Downsizing data width function ... The downsizer does not merge data narrower than the destination bus if the transaction is marked as non-cacheable....
Read more >
Automatic image downsizing - ProPhoto Support
As needed, ProPhoto creates downsized copies at widths of 480px, 768px, ... to be reduced if your server creates 'out of memory' errors...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found