frontend-starter-kit icon indicating copy to clipboard operation
frontend-starter-kit copied to clipboard

Make Universal Iframe Resizer script

Open holloway opened this issue 7 years ago • 0 comments

For security reasons browsers don't allow iframes to know the width or height of cross-origin pages, so <iframe>s often don't exactly fit the page being iframed.

To work around this a popular technique is to use JavaScript on both pages and to exchange messages (via hashes, or postMessage / [onMessage], etc.). The iframed page will tell the parent iframe page to resize the iframe itself by sending the width/height in pixels.

So that works, and we often use davidjbradshaw's iframe-resizer, but sadly there are multiple iframe resizer scripts out there (dozens of them) and each sends a slightly different message format. There are no standard protocols.

So a better iframe resizer would support multiple message formats,

  • [ ] Document the message format of every iframe resizer that you can find on Github etc.
  • [ ] Write an iframe resizer that can just sniff the message and figure out the width/height from these messages, perhaps even guessing (within a sanity check range of reasonable values)
  • [ ] Publish an NPM package for this.

holloway avatar Jul 02 '18 02:07 holloway