How to Pass URL Parameters to an Embedded iframe

Follow

If a page contains an iframe in an HTML block, you can pass the page's own URL query parameters through to the iframe's source. This is useful when the embedded page needs values from the parent URL, such as tracking parameters.

This is community code, not an official Unbounce feature. Unbounce Support can't troubleshoot custom code. Test it on a published page before relying on it.

Pass the parameters to the iframe

Give your iframe an id, leave its src empty, and set the source when the page loads. Replace the base URL with the address you want to load inside the iframe:

<iframe id="iframe" src="" width="100%" height="800" frameborder="0"></iframe>
<script>
  var baseUrl = 'https://your-embedded-page.com/';
  var params = window.location.search; // the parent page's query string, including the leading "?"
  document.getElementById('iframe').src = baseUrl + params;
</script>

When the page loads, the iframe's src becomes your base URL followed by the query string from the page URL.