-2

I used PHP code to send UTM code to an iframe. But how to translate it to javascript code?

<?php 
  $utm_source = $_GET['utm_source']; 
  $utm_medium = $_GET['utm_medium']; 
  $utm_campaign = $_GET['utm_campaign']; 
?> 
<iframe id="typeform-full" width="100%" height="100%" 
 frameborder="0" src="artsenzondergrenzen.typeform.com/to/rdm3VJ?utm_source=<?php echo $utm_source; ?>&utm_medium=<?php echo $utm_medium; ?>&utm_campaign=<?php echo $utm_campaign; ?>"></iframe> 
  <script type="text/javascript" src="embed.typeform.com/embed.js"></script>
mplungjan
  • 169,008
  • 28
  • 173
  • 236
  • Welcome to Stackoverflow. Please visit the [help], take the [tour] to see what and [ask]. Do some research, search for related topics on SO; if you get stuck, post a [mcve] of your attempt, noting input and expected output in the Question, not in a comment. Also we are not a translating service – mplungjan Mar 28 '19 at 08:08
  • Welcome to StackOverflow, it is preferred to put the code in the question itself rather than in a comment. Thank you :) – Ameen Mar 28 '19 at 08:09
  • Also it is not clear what you mean by "sending UTM code to an iframe" - you could use document.createElement or document.write instead, but I do not see why you would want to – mplungjan Mar 28 '19 at 08:10

1 Answers1

0

Thank you for your reply. I am new and will put the code in the question itself next time, thanks for helping me with that. My question is that i have a perfectly working php code for adding utm parameters from the host URL to the iFrame URL. That's an question i've seen many times on Stack. So should be helpfull for other users aswell. The problem i have i want to use it on a page that only allows html files and not php. That is why i want to translate is to javascript code. But the code below is not working, any ideas?

<script language="JavaScript">

var nl = getNewLine()

function getNewLine() {
 var agent = navigator.userAgent

 if (agent.indexOf("Win") >= 0)
  return "\r\n"
 else
  if (agent.indexOf("Mac") >= 0)
   return "\r"

  return "\r"

}

pagecode = '<?php'+nl+
 '$utm_source = $_GET[\'utm_source\'];'+nl+
 '$utm_medium = $_GET[\'utm_medium\'];'+nl+
 '$utm_campaign = $_GET[\'utm_campaign\'];'+nl+
 '?>'+nl+nl+
 '<iframe id="typeform-full" width="100%" height="100%" frameborder="0" src="https://artsenzondergrenzen.typeform.com/to/rdm3VJ?utm_source='<?php echo $utm_source; ?>'&utm_medium='<?php echo $utm_medium; ?>'&utm_campaign='<?php echo $utm_campaign; ?>'"></iframe> '+nl+nl+
 '<scr'+'ipt type="text/javascript" src="https://embed.typeform.com/embed.js"></scr'+'ipt>'

document.write(pagecode);

</script>
  • Hi Jasper :) Welcome to StackOverflow! I would recommend to paste the top answer as part of the question. Or close this question and start over: sharing the context and the code all together. – picsoung Mar 29 '19 at 18:38
  • Also, I think you it looks like a similar question to this one (https://stackoverflow.com/questions/49534280/pass-url-parameters-to-a-embedded-forms-iframes-on-landingpages/) And everything could be done in Javascript, without PHP in the middle. – picsoung Mar 29 '19 at 18:40