How to set iframe Src from JavaScript

Solved
Highlighted
Explorer
43 5 4

Hi,

I've created a new page template, you can review it here:

https://hodiva.com/pages/test-tracking?tracking=0100668631422

 

As you can see in the Alert window, the script produces the desired url,

but I can't find how to set that as the iframe Src

 

heres the full code of my new page template:

<!-- /templates/page.full-width.liquid -->
<header class="section-header text-center">
  <h1>{{ page.title }}</h1>
  <hr class="hr--small">
</header>
<script>
document.addEventListener("DOMContentLoaded", function(){
var mainParameter = window.location.search;
var address = "https://dealtas.com/tracking"
var combined = address + mainParameter;
var iframeSrcValue = document.getElementById("MyFrame").src;

  alert(combined);
});
</script>
<body>
<iframe id="MyFrame" style="width:100%;height:800px;overflow:scroll;"></iframe>
</body>
<div class="rte">
  {{ page.content }}
</div>

 

Assistance is greatly appreciated.

0 Likes
Highlighted

Success.

Explorer
43 5 4

I worked it out:

 

<body> 
<iframe id="MyFrame" style="width:100%;height:800px;overflow:scroll;"></iframe>
<script>document.addEventListener("DOMContentLoaded", function(){
var mainParameter = window.location.search;  //Change the url suffix here!
var address = "https://enter the url here"
var combined = address + mainParameter;
var iframeSrcValue = document.getElementById("MyFrame").src;document.getElementById('MyFrame').setAttribute("src", combined); //sends the value to the iframe src!
});
</script>
</body>
0 Likes