Logo

IFrame

IFrame embeds external content from another HTML document into the current page. It provides security controls through sandbox and allow attributes, and supports features like fullscreen display and referrer policy configuration.
Key features:
  • External content embedding: Load web pages, documents, or media from external URLs
  • Security controls: Built-in sandbox and permission policies for safe content isolation
  • HTML content support: Display inline HTML content without external sources
  • Event handling: Track loading states with load events

Properties

allow

Specifies the permissions policy for the iframe. Controls which features (like camera, microphone, geolocation) the embedded content can use.
The allow property controls which browser features the embedded content can access. Common values include camera, microphone, geolocation, and fullscreen permissions.
<App>
  <IFrame
      src="https://www.youtube.com/embed/dQw4w9WgXcQ"
      allow="camera; microphone; geolocation"
      width="560px"
      height="315px"
      title="Rick Astley - Never Gonna Give You Up (Official Video)"
    />
</App>
Example: allow
<App>
  <IFrame
      src="https://www.youtube.com/embed/dQw4w9WgXcQ"
      allow="camera; microphone; geolocation"
      width="560px"
      height="315px"
      title="Rick Astley - Never Gonna Give You Up (Official Video)"
    />
</App>

name

Specifies a name for the iframe, which can be used as a target for links and forms.
<App>
  <VStack gap="$space-2">
    <Button 
      label="Open 'Kraftwerk: The Model' in IFrame" 
      onClick="window.open('https://www.youtube.com/embed/-s4zRw16tMA', 'myFrame')" 
    />
    <IFrame 
      src="https://example.com"
      name="myFrame"
      width="100%" 
      height="300px" />
  </VStack>
</App>
Example: name
<App>
  <VStack gap="$space-2">
    <Button 
      label="Open 'Kraftwerk: The Model' in IFrame" 
      onClick="window.open('https://www.youtube.com/embed/-s4zRw16tMA', 'myFrame')" 
    />
    <IFrame 
      src="https://example.com"
      name="myFrame"
      width="100%" 
      height="300px" />
  </VStack>
</App>

referrerPolicy

Controls how much referrer information is sent when fetching the iframe content.
Available values:
ValueDescription
no-referrerNever send referrer information
no-referrer-when-downgradeSend referrer only for same-security destinations
originSend only the origin as referrer
origin-when-cross-originSend full URL for same-origin, origin only for cross-origin
same-originSend referrer only for same-origin requests
strict-originSend origin only for same-security destinations
strict-origin-when-cross-originFull URL for same-origin, origin for cross-origin same-security
unsafe-urlAlways send full URL as referrer

sandbox

Applies extra restrictions to the content in the iframe. Value is a space-separated list of sandbox flags (e.g., 'allow-scripts allow-same-origin').

src

Specifies the URL of the document to embed in the iframe. Either src or srcdoc should be specified, but not both.
<App>
  <IFrame 
    src="https://example.com" 
    width="100%" 
    height="300px" />
</App>
Example: src
<App>
  <IFrame 
    src="https://example.com" 
    width="100%" 
    height="300px" />
</App>

srcdoc

Specifies the HTML content to display in the iframe. Either src or srcdoc should be specified, but not both.
<App>
  <IFrame 
    srcdoc="
      <h1>Hello World</h1>
      <p>This is embedded HTML content with <strong>formatting</strong>.</p>
    "
    width="100%" 
    height="200px" />
</App>
Example: srcdoc
<App>
  <IFrame 
    srcdoc="
      <h1>Hello World</h1>
      <p>This is embedded HTML content with <strong>formatting</strong>.</p>
    "
    width="100%" 
    height="200px" />
</App>

Events

load

This event is triggered when the IFrame content has finished loading.
<App var.loadStatus="Loading...">
  <VStack gap="$space-2">
    <Text value="Status: {loadStatus}" />
    <IFrame 
      src="https://example.com"
      onLoad="loadStatus = 'Content loaded successfully!'"
      width="100%" 
      height="200px" />
  </VStack>
</App>
Example: load
<App var.loadStatus="Loading...">
  <VStack gap="$space-2">
    <Text value="Status: {loadStatus}" />
    <IFrame 
      src="https://example.com"
      onLoad="loadStatus = 'Content loaded successfully!'"
      width="100%" 
      height="200px" />
  </VStack>
</App>

Exposed Methods

getContentDocument

This method returns the content document of the iframe element.
Signature: getContentDocument(): Document | null
Get access to the iframe's content document object. Returns null if the content document is not accessible.
<App>
  <VStack var.iFrameTitle="<not queried yet>" >
    <Button 
      label="Get Document Title" 
      onClick="
        const contentDoc = myIframe.getContentDocument();
        iFrameTitle = contentDoc 
          ? contentDoc.title 
          : 'Content document not accessible';
      " />
    <Card title="IFrame title: {iFrameTitle}" />
    <IFrame 
      id="myIframe"
      srcdoc="
        <html>
          <head><title>My Awesome Document</title></head>
          <body><h1>Awesome Content</h1></body>
        </html>"
      width="100%" 
      height="200px" />
  </VStack>
</App>
Example: getContentDocument
<App>
  <VStack var.iFrameTitle="<not queried yet>" >
    <Button 
      label="Get Document Title" 
      onClick="
        const contentDoc = myIframe.getContentDocument();
        iFrameTitle = contentDoc 
          ? contentDoc.title 
          : 'Content document not accessible';
      " />
    <Card title="IFrame title: {iFrameTitle}" />
    <IFrame 
      id="myIframe"
      srcdoc="
        <html>
          <head><title>My Awesome Document</title></head>
          <body><h1>Awesome Content</h1></body>
        </html>"
      width="100%" 
      height="200px" />
  </VStack>
</App>

getContentWindow

This method returns the content window of the iframe element.
Signature: getContentWindow(): Window | null
Get access to the iframe's content window object. Returns null if the content window is not accessible.
<App>
  <VStack var.windowStatus="Not checked yet" gap="$space-2">
    <Button 
      label="Check Content Window" 
      onClick="
        const contentWindow = myIframe.getContentWindow();
        windowStatus = contentWindow 
          ? 'Content window is accessible' 
          : 'Content window is not accessible';
      " />
    <Card title="Status: {windowStatus}" />
    <IFrame 
      id="myIframe"
      src="https://example.com"
      width="100%" 
      height="200px" />
  </VStack>
</App>
Example: getContentWindow
<App>
  <VStack var.windowStatus="Not checked yet" gap="$space-2">
    <Button 
      label="Check Content Window" 
      onClick="
        const contentWindow = myIframe.getContentWindow();
        windowStatus = contentWindow 
          ? 'Content window is accessible' 
          : 'Content window is not accessible';
      " />
    <Card title="Status: {windowStatus}" />
    <IFrame 
      id="myIframe"
      src="https://example.com"
      width="100%" 
      height="200px" />
  </VStack>
</App>

postMessage

This method sends a message to the content window of the iframe.
Signature: postMessage(message: any, targetOrigin?: string): void
  • message: The message to send to the iframe's content window.
  • targetOrigin: The origin to which the message should be sent. Defaults to '*'.
<App>
  <VStack var.messageStatus="Ready to send" gap="$space-2">
    <Button 
      label="Send Message to IFrame" 
      onClick="
        myIframe.postMessage({type: 'greeting', text: 'Hello from parent!'}, '*');
        messageStatus = 'Message sent!';
      " />
    <Card title="Status: {messageStatus}" />
    <IFrame 
      id="myIframe"
      srcdoc="
        <script>
          window.addEventListener('message', (event) => \{
            console.log('Received message:', event.data);
            document.body.innerHTML = 
              '<h1>Message: ' + JSON.stringify(event.data) + '</h1>';
          });
        </script>
        <h1>Waiting for message...</h1>
      "
      width="100%" 
      height="200px" />
  </VStack>
</App>
Example: postMessage
<App>
  <VStack var.messageStatus="Ready to send" gap="$space-2">
    <Button 
      label="Send Message to IFrame" 
      onClick="
        myIframe.postMessage({type: 'greeting', text: 'Hello from parent!'}, '*');
        messageStatus = 'Message sent!';
      " />
    <Card title="Status: {messageStatus}" />
    <IFrame 
      id="myIframe"
      srcdoc="
        <script>
          window.addEventListener('message', (event) => \{
            console.log('Received message:', event.data);
            document.body.innerHTML = 
              '<h1>Message: ' + JSON.stringify(event.data) + '</h1>';
          });
        </script>
        <h1>Waiting for message...</h1>
      "
      width="100%" 
      height="200px" />
  </VStack>
</App>

Styling

Size Control

IFrame supports these theme variables for consistent sizing:
  • width-IFrame
  • height-IFrame
  • borderRadius-IFrame
  • border-IFrame
<App>
  <Theme 
    width-IFrame="400px" 
    height-IFrame="250px"
    borderRadius-IFrame="8px"
    border-IFrame="2px solid $primaryColor">
    <IFrame src="https://example.com" />
  </Theme>
</App>
Example: IFrame with custom styling
<App>
  <Theme 
    width-IFrame="400px" 
    height-IFrame="250px"
    borderRadius-IFrame="8px"
    border-IFrame="2px solid $primaryColor">
    <IFrame src="https://example.com" />
  </Theme>
</App>

Theme Variables

VariableDefault Value (Light)Default Value (Dark)
border-IFrame1px solid $borderColor1px solid $borderColor
borderBottom-IFramenonenone
borderBottomColor-IFramenonenone
borderBottomStyle-IFramenonenone
borderBottomWidth-IFramenonenone
borderColor-IFramenonenone
borderEndEndRadius-IFramenonenone
borderEndStartRadius-IFramenonenone
borderHorizontal-IFramenonenone
borderHorizontalColor-IFramenonenone
borderHorizontalStyle-IFramenonenone
borderHorizontalWidth-IFramenonenone
borderLeft-IFramenonenone
color-IFramenonenone
borderLeftStyle-IFramenonenone
borderLeftWidth-IFramenonenone
borderRadius-IFrame$borderRadius$borderRadius
borderRight-IFramenonenone
color-IFramenonenone
borderRightStyle-IFramenonenone
borderRightWidth-IFramenonenone
borderStartEndRadius-IFramenonenone
borderStartStartRadius-IFramenonenone
borderStyle-IFramenonenone
borderTop-IFramenonenone
borderTopColor-IFramenonenone
borderTopStyle-IFramenonenone
borderTopWidth-IFramenonenone
borderHorizontal-IFramenonenone
borderVerticalColor-IFramenonenone
borderVerticalStyle-IFramenonenone
borderVerticalWidth-IFramenonenone
borderWidth-IFramenonenone
height-IFrame300px300px
width-IFrame100%100%
This site is an XMLUI™ app.