Loading...
Profile Image

Profile Image

Allowing ScaleGrowth iFrames to navigate your parent page

Allowing ScaleGrowth iFrames to navigate your parent page

About

For certain use-cases, you may want to enable embedded ScaleGrowth iFrames to redirect your parent page. For example, if you want your visitors to be able to click to RSVP to Events within the iFrame.



Content

To support this kind of use-case, you will need to hook up a way for our embedded iFrame view.


Good news is, our team has prepared everything for you!

All you need to do is paste this piece of JavaScript code on any parent page that is embedding our Events iFrames:


</code></p><p><code> export function listenForSgIframeMessage() {</code></p><p><code> window.addEventListener('message', function(event) {</code></p><p><code> // Check the origin of the message</code></p><p class="sg-cursor-marker"><code> if (event.origin !== 'https://<strong><em>[[your.scalegrowth.domain]]</em></strong>') {</code></p><p><code> console.warn('Message from untrusted origin:', event.origin);</code></p><p><code> return;</code></p><p><code> }</code></p><p><code> // Extract the data from the message</code></p><p><code> const { goToUrl } = event.data;</code></p><p><code> // Ensure the message contains the goToUrl key</code></p><p><code> if (goToUrl) {</code></p><p><code> console.log('Received URL:', goToUrl);</code></p><p><code> // Redirect to the received URL</code></p><p><code> window.location.href = goToUrl;</code></p><p><code> } else {</code></p><p><code> console.warn('Invalid message format received');</code></p><p><code> }</code></p><p><code> });</code></p><p><code> }</code></p><p><code> listenForSgIframeMessage();</code></p><p><code>


Our team is always happy to help with this integration. Please post under Ask SG Team in your Success Center with any questions.