Solved

How to set iframe Src from JavaScript

ZivHodiva
Explorer
45 6 11

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.

Accepted Solution (1)

ZivHodiva
Explorer
45 6 11

This is an accepted solution.

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>

View solution in original post

Reply 1 (1)

ZivHodiva
Explorer
45 6 11

This is an accepted solution.

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>