a-iframe Custom Element

A custom element that wraps a standard iframe element, providing automatic height resizing based on the content's size and proxying standard iframe attributes.

Tests

README

Basic Example

Code

Using Inline HTML

You don't have to use a separate HTML file. You can also write your HTML inline.

Code

Including Scripts in Inline HTML

Code

Passing iframe Attributes

Code

Sandboxing

If you sandbox the iframe and your HTML is inline or is a local file, the sandbox attribute must include allow-same-origin. Otherwise the iframe will not resize.

Chromium based browsers will log an error, "Blocked script execution ..." but a-iframe will work correctly. The error is simply telling you that the sandbox is preventing script execution within the iframe.

Important!

If the sandbox also includes allow-scripts, make sure you trust the content (or sanitize it before injecting it into a-iframe).

If both flags are present and the iframe content shares the parent's origin, the iframe's scripts can access window.parent.document. The script can then remove the sandbox attribute from its own iframe element or steal your site's cookies and local storage (XSS).

Code

Cross-origin iframes

Code