iframe
Helpers for reading and controlling iframe content — window/document
access, postMessage, src changes, reloading, and load detection.
Import: @rtorcato/browser-common/iframe
Example
import {
isIframe,
postMessageToIframe,
onIframeLoad,
} from '@rtorcato/browser-common/iframe'
if (isIframe(el)) {
onIframeLoad(el, () => console.log('iframe ready'))
postMessageToIframe(el, { type: 'ping' }, 'https://example.com')
}
Exports
isIframe(el)— type guard forHTMLIFrameElementgetIframeWindow(iframe)— returnscontentWindowornullgetIframeDocument(iframe)— returnscontentDocumentornullpostMessageToIframe(iframe, message, targetOrigin?)— posts a message to the iframe's windowsetIframeSrc(iframe, url)— sets the iframe'ssrcreloadIframe(iframe)— reloads the iframe's contentisIframeLoaded(iframe)— true oncecontentDocument.readyStateis'complete'onIframeLoad(iframe, callback)— adds aloadevent listener
See the API reference for full signatures.