SEB Magic Iframe

April 8, 2020 ยท View on GitHub

Most options (properties) below can be set using element attributes e.g.

<seb-magic-iframe auto-resize="false"></seb-magic-iframe>

For more complex options or when you need to pass objects or arrays like for styleUrls, you need to pass the value using JavaScript e.g.

html

<seb-magic-iframe id="magicIframe"></seb-magic-iframe>

js

const magicIframe = document.getElementById('magicIframe');
magicIframe.styleUrls = ['/css/external-stylesheet.css', '/css/fonts.css']

Properties

PropertyAttributeDescriptionTypeDefault
autoResizeauto-resizeResize the iframe when the inner content changes height.booleantrue
debugdebugPrint debug log (console log).booleanfalse
matchContentWidthmatch-content-widthSet width of magic iframe to width of iframe content, useful when iframing fixed width pages."auto" | booleanfalse
maxHeightmax-heightPrevent the iframe from growing infinitely by setting a max height i.e. prevent infinite loop for height value when iframe content height depends on container height.string'10000vh'
minWidthmin-widthSet a min width for the iframe.stringundefined
reloadOnChangereload-on-changeForce reload of iframe when source changes, useful for SPA:s that won't refresh otherwise.booleanfalse
resizeDebounceresize-debounceDebounce time in milliseconds for resize event.number0
sanitizeSourcesanitize-sourceSanitize url:s (both for iframe and external stylesheets) to prevent XSS attacks.booleantrue
scaleContentscale-contentScale content inside iframe to match with of iframe, useful when iframing fixed width pages.booleanfalse
scaleDebouncescale-debounceDebounce time in milliseconds for scale event.number0
sourcesourceUrl to iframe content.stringundefined
styleUrls--Add one or more stylesheets to the iframe, note that the iframe won't be visible until they've loaded.string[]undefined
stylesstylesApply/inject inline styles to the iframe.stringundefined

Events

EventDescriptionType
magicIframeEventListen to events emitted by magic iframe e.g.
 const magicIframe = document.getElementById('magicIframe');
magicIframe.addEventListener('magicIframeEvent', event=>console.log(event => console.log(event.detail));
CustomEvent<MagicIframeEvent>

Type <MagicIframeEvent>

MagicIframeEvent {
  event: MagicIframeEventName;
  details: any | MouseEvent | KeyboardEvent;
}

Type <MagicIframeEventName>

EventDescription
iframe-clickEmitted when element inside iframe has been clicked.
iframe-keyupEmitted when keyup event emitted inside iframe.
iframe-styles-addedEmitted when styles have been added.
iframe-styles-removedEmitted when styles have been removed.
iframe-stylesheet-loadEmitted when external stylesheets start loading.
iframe-stylesheet-loadedEmitted when external stylesheets have finished loading.
iframe-all-stylesheets-loadedEmitted when all external stylesheets have finished loading (only emitted if more than one external stylesheets).
iframe-all-stylesheets-removedEmitted when all external stylesheets have been removed.
iframe-loadedEmitted when iframe has finished loading (including optional styles and/or stylesheets).
iframe-loaded-with-errorsEmitted when iframe has encountered errors after loading (usually related to CORS and inability to access iframe content).
iframe-unloadedEmitted when iframe triggers unload event (url in iframe changes).
iframe-removedEmitted when iframe element is removed from DOM (no source provided).
iframe-resizedEmitted when iframe is resized to fit content height.
iframe-content-scaledEmitted when iframe content is scaled to fit iframe size.
iframe-title-changeEmitted when the page title for the iframe content has changed.