Using a SharinPix component in an Iframe (Developer-oriented)
In this article, you will learn:
The Iframe syntax used by SharinPix
How to create a Visualforce page that contains an Iframe embedding the SharinPix component
Iframe syntax used by SharinPix
SharinPix is flexible enough to be used in an Iframe. Traditionally, the Iframe syntax used to embed a SharinPix component was as follows:
<apex:page standardController="Account" extensions="GetToken">
<iframe id="iframeId" class="sharinpix-iframe" src="https://app.sharinpix.com/?token={! SharinPixToken }"></iframe>
</apex:page>However, some iOS devices encountered a cookie issue when using this syntax as depicted in the image below:

To bypass this issue, SharinPix made use of the **postMessage **method (a method that ensures cross-document messaging between two domains) to send the token to the SharinPix URL.
The postMessage method takes two arguments:
The data to be sent.
The domain to which you want to send the data. This domain is commonly referred to as the** target origin**.
In the following section, you will learn how a SharinPix component can be embedded in an Iframe using the **postMessage **method. To demonstrate this, we will:
Create an Apex method that generates the token.
Create a Visualforce page that:
Embeds an Iframe containing the SharinPix URL and a reference to the postMessage method.
Invokes the Apex method to retrieve the token.
Creating the Visualforce page
**Note: **For this demo, we will use the Account object.
This section shows how to create the Visualforce page that will:
Embed an Iframe.
Invoke the newly-created method that returns a token**.**
Use the postMessage method to send the retrieved token to the target origin.
Firstly, create an Apex Class containing a method that generates a token and returns same using the code snippet below:
Now create the Visualforce page using the code snippet below:
The newly-created Visualforce page consists of an Iframe embedding the SharinPix URL and a reference to the postMessage method.
Upon loading the Iframe, the Visualforce page will invoke the method **generateToken **from the class **GetToken **to retrieve the token.
The retrieved token will be then sent to the target origin using the postMessage method as shown in the code snippet below:
See the Iframe in Action
To access the SharinPix component from the Iframe, add the newly-created Visualforce page to an Account object.

Last updated

