0.1.3 • Published 2 years ago

seamless-iframe v0.1.3

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

Seamless Iframe 🔮

Build Build ESlint Size Dependencies Coverage

Seamless Iframe is a customisable React component that allows you to render HTML content in an iframe and makes it look as if it was part of the page itself. Seamless! 👻

Quick examples

🎨 Inherits styles from the parent document and vertically updates its height

Demo for style and resize

🔗 Handle user clicks on links

Demo for handling link clicks

Usage

import { SeamlessIframe } from "seamless-iframe";

const myHtml = sanitize("<div>hello</div>"); // HTML sanitisation is still recommended.

export const MyPage = (props) => {
    return ( 
        <SeamlessIframe
            sanitizedHtml={myHtml}
            customStyle={`
                body {
                    font-family: sans-serif;
                }
            `}
        />
    );
}

Props

PropertyTypeDescriptionDefault
sanitizedHtmlStringRequired - HTML string of text to be rendered in the iframe. We suggest to sanitize the HTML before passing to the component.-
inheritParentStyleBooleanWhether to inherit styles on the parent page or nottrue
titleStringTitle of the iframe, important for accessibility""
customStyleStringExtra set of css rules for the inner contentbody { margin: 0; padding: 0; }
customScriptStringExtra script to be added to the iframe body
heightCorrectionBooleanWhether to apply the iframe content scroll height to the iframe element or nottrue
heightCorrectionOnResizeBooleanWhether to re apply the height on resize. Off is heightCorrection is falsetrue
debounceResizeTimeNumberDebounce time for reapplying height on the window resize event. If set to 0, no debounce function will be applied250
interceptLinkClicksBooleanWhether to listen to link clicks. If enabled, the parent window will show a confirmation whenever a link in the iframe gets clickedfalse
customLinkClickCallbackFunctionFunction to manipulate the behaviour of the top window on link click. Useless if interceptLinkClicks is falsy.-
preventIframeNavigationBooleanWhether to prevent the iframe to navigate to a different URL. If a script inside the iframe tries to change the iframe window location, Seamless Iframe will repaint from the initial state. If this happens multiple times, a warning view gets displayed instead of the iframe.true
customIframeNavigationInterceptedViewReactElementReplace the default warning view when iframe tries to navigate away.-

Abstract

What does this library do?

It provides a React component with a set of utilities to render custom HTML in an iframe that looks as if it was part of your page.

Normal iframes in fact: 1. don't inherit styles from the parent window 1. don't provide an easy way to set their full height 1. don't allow users to open links on the top level window 1. don't prevent scripts to change the iframe location

Here's where SeamlessIframe comes in handy. The generated iframes will automatically set their height depending on the content, and they will inherit the parent window or custom styles. In addition, it allows you to quickly customise what happens when a user clicks on a link. If a script (that somehow made it through the sanitization process) inside the iframe tries to manipulate the location (url) of the iframe, SeamlessIframe will intercept it and prevent it from happening.

Why would you use an iframe to render html?

In summary, further security.

There are a number of great sanitized libraries out there that prevents malicious scripts from being injected in your page.

However, if these libraries fail is good to have another layer of security. Iframes and their powerful sandbox attribute prevents a number of potentially dangerous behaviours.

0.1.3

2 years ago

0.1.3-rc2

3 years ago

0.1.3-rc1

3 years ago

0.1.2

3 years ago

0.1.2-rc1

3 years ago

0.1.0

3 years ago

0.1.1

3 years ago

0.1.1-rc1

3 years ago

0.0.6-rc7

3 years ago

0.0.5-rc3

3 years ago

0.0.5-rc4

3 years ago

0.0.5-rc2

3 years ago

0.0.6-rc6

3 years ago

0.0.5-rc5

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.4-rc1

3 years ago

0.0.3

3 years ago

0.0.3-rc12

3 years ago

0.0.3-rc11

3 years ago

0.0.3-rc10

3 years ago

0.0.3-rc9

3 years ago