Dynamic iFrame src (without using the Webflow CMS)

Hey,

i would like to dynamically change the src link of an iFrame via JavaScript var (without using the Webflow CMS). Unfortunately I am reaching my limits with my custom code and hope you can help me at this point. Here is my code so far:

page custom code

<script>
  window.onload = function() {
    var myVar = "https://google.com";
    var myIframe = document.getElementById('myEmbedIframe');
    myIframe.setAttribute("src", myVar);
  }
</script>

iFrame code

<iframe 
  src=myVar
  width="100%"
  height="533"
></iframe>