将javascript变量解析为iframe src

将javascript变量解析为iframe src,javascript,variables,iframe,click,Javascript,Variables,Iframe,Click,我被要求在网站订单接收页面上部署一个点击值跟踪像素。数据必须动态地放置到iframe的src中 我已将正确的数据声明为变量,如下所示: <script type="text/javascript"> //makes a copy of the total order revenue var totalPrice = jQuery('.veryImportant.ordertotal div').html(); jQuery('#buttons').append('<p id="

我被要求在网站订单接收页面上部署一个点击值跟踪像素。数据必须动态地放置到iframe的src中

我已将正确的数据声明为变量,如下所示:

<script type="text/javascript">
//makes a copy of the total order revenue
var totalPrice = jQuery('.veryImportant.ordertotal div').html();
jQuery('#buttons').append('<p id="totalPrice">'+totalPrice+'</p>');
//removes the £ pound symbol from the duplicated string
var val = jQuery('#totalPrice').html();
jQuery('#totalPrice').html(val.substring(1, val.length));
//required variables
var orderid = jQuery('.ordernumber strong').text(); //order ID number
var revenue = jQuery('#totalPrice').text(); // total order revenue
var quantity = jQuery('#totalQuantity').text(); //quantity per table row/product name
//testing the variables print the correct values
alert(orderid + " " + revenue + " " + sku + " " + quantity);
</script>

//制作订单总收入的副本
var totalPrice=jQuery('.veryiimportant.ordertotal div').html();
jQuery(“#按钮”).append(“

”+totalPrice+”

”); //从复制的字符串中删除英镑符号 var val=jQuery('#totalPrice').html(); jQuery('#totalPrice').html(val.substring(1,val.length)); //必需变量 var orderid=jQuery('.ordernumber strong').text()//订单ID号 var revenue=jQuery(“#totalPrice”).text();//订单总收入 var quantity=jQuery('#totalQuantity').text()//每表行数量/产品名称 //测试变量打印正确的值 警报(订单ID+“”+收入+“”+sku+“”+数量);
(对于任何想知道“sku”的人来说,这已经存在于页面中,所以我很幸运)

我需要变量在这个iframe中动态打印它们的值,我将把它放在上面的jQuery下面:

<iframe src="https://secure.img-cdn.mediaplex.com/0/24663/universal.html?page_name=sale&Sale=1&Amount={' + revenue + '}&Quantity={' + quantity + '}&mpuid={' + sku + ',' + orderid + '}" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe>

在上面,我尝试添加变量名,但用空格和+符号封装,但不起作用。它只是在浏览器中准确地显示上述内容


大家有什么想法吗?

好的,所以我设法解决了这个问题。这个方法相当冗长,但遗憾的是,我必须克服一些障碍(因此我必须复制和移动一些数据)


var totalPrice=jQuery('.veryiimportant.ordertotal div').html()//从收据中获取订单总价并将其存储在变量中 jQuery(“#按钮”).append(“

”+totalPrice+”

”)//打印p标签内的总价,以便选择 var val=jQuery('#totalPrice').html()//从上面新打印的p标签中获取订单总价 jQuery('#totalPrice').html(val.substring(1,val.length))//从#totalPrice字符串中删除第一个字符(在本例中为不需要的英镑符号) var orderid=jQuery('.ordernumber strong').text()//订单ID号 var revenue=jQuery(“#totalPrice”).text();//订单总收入 var quantity=jQuery('#totalQuantity').text()//每表行数量/产品名称 //sku是一个似乎已经在默认签出页面js中的变量。我很幸运有这个。 警报(订单ID+“”+收入+“”+sku+“”+数量)//测试所有变量是否按应有的方式打印 jQuery('#valueClickSrc').html('https://secure.img-cdn.mediaplex.com/0/24663/universal.html?page_name=sale&Sale=1&Amount=%7b“+收入+'%7d&数量=%7b'+数量+'%7d&mpuid='+sku+'id'+orderid”)//使用文本和变量的组合写入动态url。这被放置在上面称为#valueClickSrc的中 var valueClickSrc=jQuery('#valueClickSrc').html()//将上述的内容存储到变量中 jQuery('#iframe1').attr('src',valueClickSrc)//将#valueClickSrc中的内容应用到iframe的src属性中
对于在Venda平台上工作的任何人来说,他们可能会发现这很有用


如果有人有建议,我很乐意听取。

只是为了确保,您希望这些变量作为iframe html中的文本?是的,这是正确的。在警报框中调用变量时,变量包含正确的文本。
<!-- order confirmation page VALUE CLICK -->
<venda_block mode=value,<venda_tpxt mode=get,name=track>=orderreceipt><!-- applies this     code block to the order receipt page only -->
<!-- HTML -->
<p id="valueClickSrc"></p><!-- acts as a store for the js to construct and deploy the dynamic src -->
<iframe id="iframe1" src="#" HEIGHT=1 WIDTH=1 FRAMEBORDER=0></iframe> <!-- the actual      tracking iframe which will be populated by js -->
<p id="totalQuantity" style="position:relative; z-index:9999; background:#066; font-size:14px; color:#FFF;"><venda_shopcart mode=getqty></venda></p><!-- serves to 'wrap' the quantity so that it can be selected by id -->
<!-- witch craft -->
<script type="text/javascript">
var totalPrice = jQuery('.veryImportant.ordertotal div').html(); //grabs the order total     price from the receipt and stores it in a variable
jQuery('#buttons').append('<p id="totalPrice" style="display:none;">'+totalPrice+'</p>'); //prints the total price inside a p tag so that it can be selected
var val = jQuery('#totalPrice').html(); //grabs the order total price from the newly printed p tag above
jQuery('#totalPrice').html(val.substring(1, val.length)); //removes the first character from the #totalPrice string (in this case, the unwanted £ GBP pound symbol)
var orderid = jQuery('.ordernumber strong').text(); //order ID number
var revenue = jQuery('#totalPrice').text(); // total order revenue
var quantity = jQuery('#totalQuantity').text(); //quantity per table row/product name
// sku is a variable that appears to already be in side the default checkout page js. I got lucky with that one.
alert(orderid + " " + revenue + " " + sku + " " + quantity); //tests that all variables are printing as they should
jQuery('#valueClickSrc').html('https://secure.img-cdn.mediaplex.com/0/24663/universal.html?page_name=sale&Sale=1&Amount=%7b'+revenue+'%7d&Quantity=%7b'+quantity+'%7d&mpuid='+sku+'id'+ orderid); //writes the dynamic url with a combination of text and variables. This is placed inside the <p> above called #valueClickSrc
var valueClickSrc = jQuery('#valueClickSrc').html(); //stores the content of the <p> above into a variable
jQuery('#iframe1').attr('src', valueClickSrc); //applies the content from #valueClickSrc into the src attribute of the iframe
</script>
</venda_block>
<!-- End Value Click tag -->