1

I'm a bit new to JavaScript and have been searching for the answer for a couple hours before posting. I have a page that loads a form using an iframe. I have a Javascript function that parses the URL and saves the UTM values to variables.

Now I need to pass the variables to this iframe url.

<iframe id="ourIframe" onload="javascript:parent.scrollTo(0,0);" height="644" allowTransparency="true" frameborder="0" scrolling="no" style="width:100%;border:none" src="http://www.xxxxx.com/form/view.php?id=14875"></iframe>

The form is set up to accept paramters in the following format:

http://www.example.com/form/view.php?id=7&element_1_1=adwords&element_1_2=term

My javascript variables are "utm_campaign" and "utm_source" etc. So element_1_1 = utm_campaign

I hope this is pretty easy to do. I just can't figure out how to get my variable into my URL of the iframe.

Thanks! Jenny

jenny
  • 11
  • 2

1 Answers1

0

If you have this information before you render IFRAME, add it to URL as query string (?name=value) or hash (#name=value). Both information you can find in document.location object (in iframe).

If you acquire this information after render IFRAME you can use postmessage. More here: https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage

wojtekk
  • 61
  • 3