npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

magic-iframe

v0.9.1

Published

Magic IFrame Script

Downloads

12

Readme

Magic IFrame

Easy, responsive IFrames - Magic!

What is this "magic" IFrame?

Magic IFrame is a script to make iframes responsive.

Supported Browsers

This script relies on window.postMessage for communication between the parent and child pages. It also uses requestAnimationFrame but has a setTimout-based fallback for it. Currently, this works in all modern browsers and IE8+.

It requires JavaScript to work and there is no non-JavaScript fallback. Put down your tinfoil hats.

Usage — Inside IFrame

Include the following script tag inside the iframe:

<script src="magic-iframe.min.js" data-role="child"></script>

Usage — Embedding the IFrame

There are three ways to embed the responsive iframe in your page:

1. No existing IFrame tag

<script src="magic-iframe.min.js" data-role="parent" data-url="{{IFRAME_URL}}"></script>
<noscript><iframe src="{{IFRAME_URL}}" frameborder="0" style="width:100%;height:{{IFRAME_HEIGHT}}"></iframe></noscript>

The script will automatically write the iframe tag for you in its place.

If id or class attributes are present on the script tag, they will be transferred to the generated iframe tag. If an id is specified, the script will assign itself an ID in the format mif-script-{{ORIGINAL_ID}}.

2. Existing IFrame tag, method 1

<iframe id="{{IFRAME_ID}}" src="{{IFRAME_URL}}" frameborder="0" style="width:100%;height:{{IFRAME_HEIGHT}}"></iframe>
<script src="magic-iframe.min.js" data-role="parent" data-target="#{{IFRAME_ID}}"></script>

The data-target attribute can accept a selector that can be passed to document.querySelectorAll (jQuery will be used as a fallback). If the browser does not support document.querySelectorAll and jQuery is not present, only simple ID selectors are allowed.

If both the data-target and data-url attributes are present, both behaviors will be executed.

3. Existing IFrame tag, method 2

<iframe id="{{IFRAME_ID}}" src="{{IFRAME_URL}}" frameborder="0" style="width:100%;height:{{IFRAME_HEIGHT}}"></iframe>
<script src="magic-iframe.min.js"></script>
<script>
  MagicIframe.parent('#{{IFRAME_ID}}').init();
  // ... or ...
  MagicIframe.parent('[selector]').init();
  // ... or ...
  MagicIframe.parent(document.querySelector('[selector]')).init();
  // ... or ... (with jQuery)
  $('[selector]').magicIframe();
</script>

The selector rules above apply here. This method may be used alongside the two other methods without any conflicts.

If the iframe tag is not present on the page when the script is loaded (when loaded with AJAX for example), this method can be used to enable magic IFrame support on it.

Questions/Comments/Issues

Please submit an issue on this GitHub project. Pull requests are welcome!

Contributing

Clone, modify, use grunt to build, pull request. Thanks!