salesforce
  1. salesforce-apex-iframe-component

apex:iframe Component

The apex:iframe component in Salesforce's Visualforce allows you to embed an external webpage or Visualforce page into your Visualforce page.

Syntax

The basic syntax for the apex:iframe component is as follows:

<apex:iframe src="[source URL]" />

Example

To embed a Google search page within a Visualforce page, use the following code:

<apex:page>
  <apex:iframe src="https://www.google.com/search?q=salesforce" />
</apex:page>

Output

The output will be an iframe containing the Google search page for "salesforce".

Explanation

The apex:iframe component allows you to embed external webpages or Visualforce pages within your Visualforce page by specifying their source URL. This component can be useful if you want to show your users information from another site without directing them away from your page or if you want to embed a Salesforce page within another Salesforce page.

Use

You can use the apex:iframe component to embed external webpages containing relevant information for your users, or to embed Visualforce pages within other Visualforce pages.

Important Points

  • The src attribute must contain a valid URL for the page to be rendered in the iframe.
  • Content from external sources is subject to cross-site scripting (XSS) attacks, so be sure to use reputable sources and properly sanitize any user input.
  • If the apex:iframe component is used to embed a Visualforce page, the parent and child pages may have separate authentication and session contexts.

Summary

The apex:iframe component in Visualforce allows you to embed external webpages or Visualforce pages within your Visualforce page. Its simple syntax requires a valid URL in the src attribute. Beware of potential XSS attacks and separate authentication and session contexts when using apex:iframe with external or Salesforce pages.

Published on: