用于将UTM发送到iFrame的PHP代码的Javascript转换

时间:2019-03-28 08:01:53

标签: javascript php iframe utm

我使用PHP代码将UTM代码发送到iframe。但是如何将其转换为javascript代码?

<?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>

1 个答案:

答案 0 :(得分:0)

谢谢您的答复。我是新手,下次将代码放入问题本身,感谢您的帮助。我的问题是,我有一个完美的php代码,用于将utm参数从主机URL添加到iFrame URL。我在Stack上已经看过很多次了。因此对其他用户也应有所帮助。我的问题是我想在仅允许html文件而不允许php的页面上使用它。这就是为什么我要翻译的是javascript代码。但是下面的代码不起作用,有什么想法吗?

<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>