All Projects → davidjbradshaw → Iframe Resizer React

davidjbradshaw / Iframe Resizer React

Licence: mit
The official React interface for Iframe-Resizer

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Iframe Resizer React

Ngx Gallery
Angular Gallery, Carousel and Lightbox
Stars: ✭ 417 (+127.87%)
Mutual labels:  iframe
Node Iframe Replacement
An alternative to sticking that lovely web app you just built into an <iframe> on a corp website
Stars: ✭ 37 (-79.78%)
Mutual labels:  iframe
Postmate
📭 A powerful, simple, promise-based postMessage library.
Stars: ✭ 1,638 (+795.08%)
Mutual labels:  iframe
Sdk
Make any URL embeddable. Turn any URL into a beautiful link preview.
Stars: ✭ 446 (+143.72%)
Mutual labels:  iframe
Paypal Checkout Components
Javascript Integration for PayPal Button and PayPal Checkout
Stars: ✭ 938 (+412.57%)
Mutual labels:  iframe
React Frame Component
Render your React app to an iFrame
Stars: ✭ 1,163 (+535.52%)
Mutual labels:  iframe
Post Me
📩 Use web Workers and other Windows through a simple Promise API
Stars: ✭ 398 (+117.49%)
Mutual labels:  iframe
Gravity Forms Iframe
A Gravity Forms add-on to embed a form in an auto-resizing iframe on external sites.
Stars: ✭ 134 (-26.78%)
Mutual labels:  iframe
Rext
🎈A lightweight (< 5kb gzipped) and Promise-supported HTTP request library, for all browsers.
Stars: ✭ 14 (-92.35%)
Mutual labels:  iframe
Windtalk
Simplest way to communicate with iFrames and other windows
Stars: ✭ 100 (-45.36%)
Mutual labels:  iframe
Aws Lex Web Ui
Sample Amazon Lex chat bot web interface
Stars: ✭ 500 (+173.22%)
Mutual labels:  iframe
Iframe Resizer
Keep same and cross domain iFrames sized to their content with support for window/content resizing, in page links, nesting and multiple iFrames
Stars: ✭ 5,585 (+2951.91%)
Mutual labels:  iframe
Wheelchair
An introduction to the battle between JavaScript cheats and anti cheats.
Stars: ✭ 84 (-54.1%)
Mutual labels:  iframe
Preact Habitat
Zero configuration Preact widgets renderer in any host DOM
Stars: ✭ 444 (+142.62%)
Mutual labels:  iframe
Zoid
Cross domain components
Stars: ✭ 1,672 (+813.66%)
Mutual labels:  iframe
React Chrome Extension
chrome extension boilerplate with ReactJs using inject page strategy
Stars: ✭ 405 (+121.31%)
Mutual labels:  iframe
Muximux
A lightweight way to manage your HTPC
Stars: ✭ 1,008 (+450.82%)
Mutual labels:  iframe
Defer.js
🥇 A super small, super efficient library that helps you lazy load everything like images, video, audio, iframe as well as stylesheets, and JavaScript.
Stars: ✭ 138 (-24.59%)
Mutual labels:  iframe
Btabs
A jQuery plugin open pages in tab, based on Bootstrap2,3
Stars: ✭ 124 (-32.24%)
Mutual labels:  iframe
Vue Mpc
multiple pages (multiple entries) based on vue-cli3.x(基于vue-cli3.x创建的多页面应用,每个页面入口又可以创建自己的vue-router)
Stars: ✭ 97 (-46.99%)
Mutual labels:  iframe

iframe-resizer-react

NPM

This library is the official React interface for iframe-resizer, which enables the automatic resizing of the height and width of both same and cross domain iFrames to fit their contained content. It provides a range of features to address the most common issues with using iFrames, these include:

  • Height and width resizing of the iFrame to content size.
  • Works with multiple and nested iFrames.
  • Domain authentication for cross domain iFrames.
  • Provides a range of page size calculation methods to support complex CSS layouts.
  • Detects changes to the DOM that can cause the page to resize using MutationObserver.
  • Detects events that can cause the page to resize (Window Resize, CSS Animation and Transition, Orientation Change and Mouse events).
  • Simplified messaging between iFrame and host page via postMessage.
  • Fixes in page links in iFrame and supports links between the iFrame and parent page.
  • Provides custom sizing and scrolling methods.
  • Exposes parent position and viewport size to the iFrame.
  • Works with ViewerJS to support PDF and ODF documents.
  • Supports IE 11

Donate

Iframe-resizer is the result of many 100s of hours of work, if you would like to join others in showing support for the development of this project, then please feel free to buy me a coffee.

Buy Me A Coffee

Install

npm install --save iframe-resizer-react

Usage

The <IframeResizer /> component can be passed all<iframe> atrributes, along with options and events from iframe-resizer. You can also optionally pass a forwardRef to gain access to a few methods that provide a simple interface to communicate with the page in the iframe.

<IframeResizer
  {iframe attributes}
  {iframe-resizer options}
  {iframe-resizer events}
/>

The page in the iframe then needs (iframeResizer.contentWindow.min.js) from iframe-resizer. This file is designed to be a guest on someone else's system, so has no dependencies and won't do anything until it's activated by a message from the containing page.

Typical setup

The normal configuration is to have the iframe resize when the browser window changes size or the content of the iFrame changes. To set this up you need to configure one of the dimensions of the iFrame to a percentage and tell the library to only update the other dimension. Normally you would set the width to 100% and have the height scale to fit the content.

<IframeResizer
  log
  src="http://anotherdomain.com/iframe.html"
  style={{ width: '1px', minWidth: '100%'}}
/>

Note: Using min-width to set the width of the iFrame, works around an issue in iOS that can prevent the iFrame from sizing correctly.

Advanced Setup

This is a more advanced configuration, taken from the example folder, which demostrates the use of options, events and methods from the iframe-resizer API. See below for more details.

import React, { useRef, useState } from 'react'
import IframeResizer from 'iframe-resizer-react'

import MessageData from './message-data'

export default () => {
  const iframeRef = useRef(null)
  const [messageData, setMessageData] = useState()

  const onResized = data => setMessageData(data)

  const onMessage = data => {
    setMessageData(data)
    iframeRef.current.sendMessage('Hello back from the parent page')
  }

  return (
    <>
      <IframeResizer
        forwardRef={iframeRef}
        heightCalculationMethod="lowestElement"
        inPageLinks
        log
        onMessage={onMessage}
        onResized={onResized}
        src="http://anotherdomain.com/iframe.html"
        style={{ width: '1px', minWidth: '100%'}}
      />
      <MessageData data={messageData} />
    </>
  )
}

API Documentation

The full iframe-resizer API is supported by the <IframeResizer/> compontent, except for the methods and events used to remove an iframe from the page. Instead you should just remove the componet via JSX and it will internally call these methods for you to remove attached handlers.

Alternatives

This project uses React Hooks internally, so requires React 16.8 or later. If you are using an older version of React or require support for IE8-10 then you should checkout react-iframe-resizer-super, which is based on iframe-resizer v3.

License

MIT © davidjbradshaw

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].