
Company News
Socket Named Top Sales Organization by RepVue
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.
simple-iframe-resizer
Advanced tools
simple-iframe-resizer helps you to auto resize cross-domain iframe dimensions based on the content size
simple-iframe-resizer helps you to auto resize cross-domain iframe dimensions based on the content size
It works as react hooks, and is only compatible with React>=16.8.0
# npm
npm install simple-iframe-resizer --save
# yarn
yarn add simple-iframe-resizer
# pnpm
pnpm add simple-iframe-resizer
Two hooks are used in iframe and host respectively, useResizeChild and useResizeParent. For convenience, we treat iframe as child and host as parent.
useResizeChild: used within iframe context.useResizeParent: used within host context that containing a iframe elementUse it in both parent and child side. simple-iframe-resizer will use this event name to communicate between parent and child through postMessage. Make sure the event name is unique to avoid interference.
// Example event name
const RESIZE_EVENT_NAME = "__simple_iframe_resizer_demo_9f9292a4"
import { useResizeChild } from "simple-iframe-resizer"
function ChildApp() {
const [domRef] = useResizeChild(RESIZE_EVENT_NAME)
return <div ref={domRef}>Hello World</div>
}
import { useResizeParent } from "simple-iframe-resizer"
function ParentApp() {
const iframeRef = useRef<HTMLIFrameElement>(null)
const iframeWindowRef = useRef<Window | undefined>()
useEffect(() => {
iframeWindowRef.current = iframeRef.current?.contentWindow || undefined
}, [])
const [rect] = useResizeParent(RESIZE_EVENT_NAME, iframeWindowRef)
return (
<iframe
ref={iframeRef}
src="https://www.example.com"
height={rect.height || "100%"}
width={rect.width || "100%"}
/>
)
}
onUnmount event and reset the iframe heightconst [domRef, rpcClient] = useResizeChild(RESIZE_EVENT_NAME)
useEffect(() => {
return () => rpcClient.onUnmount()
}, [])
const [rect, childRpcClient] = useResizeParent(
RESIZE_EVENT_NAME,
iframeWindowRef,
)
useEffect(() => {
childRpcClient.getSize().then((rect) => {
console.log(rect)
})
}, [])
interface ParentFunctions {
onResize: (rect: DOMRectReadOnly) => void
onUnmount: () => void
}
interface ChildFunctions {
getSize: () => DOMRectReadOnly | undefined
}
declare const useResizeChild: <T extends Element>(
id: string,
) => [React.RefObject<T>, ParentRpcClient | undefined]
declare const useResizeParent: (
id: string,
windowRef: React.MutableRefObject<Window | undefined>,
) => [DOMRectReadOnly | undefined, ChildRpcClient | undefined]
FAQs
simple-iframe-resizer helps you to auto resize cross-domain iframe dimensions based on the content size
We found that simple-iframe-resizer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Company News
Socket won two 2026 Reppy Awards from RepVue, ranking in the top 5% of all sales orgs. AE Alexandra Lister shares what it's like to grow a sales career here.

Security News
NIST will stop enriching most CVEs under a new risk-based model, narrowing the NVD's scope as vulnerability submissions continue to surge.

Company News
/Security News
Socket is an initial recipient of OpenAI's Cybersecurity Grant Program, which commits $10M in API credits to defenders securing open source software.