1

I have a javascript that needs to be loaded on the "completion" page of an ecommerce site, here is the code:

<script type="text/javascript">
var skulist="",pricelist="",quantitylist="";
for (var i=0; i < OrderDetails.length; i++){
skulist = OrderDetails[i][2]+","+skulist;
pricelist =OrderDetails[i][5]+","+pricelist;
quantitylist =OrderDetails[i][6]+","+quantitylist;
}

skulistLen=skulist.length;

skulist = skulist.slice(0,skulistLen-1);

pricelistLen=pricelist.length;

pricelist = pricelist.slice(0,pricelistLen-1);

quantitylistLen=quantitylist.length;

quantitylist = quantitylist.slice(0,quantitylistLen-1);

document.write("<iframe height='1' width='1' frameborder='0' scrolling='no' src='https://www.emjcd.com/tags/c?containerTagId=49296&ITEM1="+skulist+"&AMT1="+pricelist+"&QTY1="+quantitylist+"&CID=10000171&OID=$(OrderNo)&TYPE=362565438&CURRENCY=USD' name='cj_conversion'></iframe>");


</script>

and I need to call it with jquery... (for other reasons) - and I am doing so like this:

<div id="cj-placeholder"><!--placeholder--></div>
<script>
if($.cookie("so-affiliate") ) {
    $().ready(function() {
    // load external file
    //$('#cj-placeholder').load('/v/js/cj.html', function() {
    //return;
    $.get('/v/js/cj.html')
 .success(function(data) {
     $('#cj-placeholder').html(data);

});
});


}else{
  $('#cj-placeholder').append('.');

}
</script>

the problem is, when I do this, I get a blank page with ONLY the contents of cj.html inside (the script) - it is replacing the order finished page instead of appending to it... by searching here, I learned that if a document.write is called like this AFTER the page is loaded then it'll replace it as it is, problem is.... what do I do?

2
  • 2
    Quick question: why are you using document.write()? Did you get that from w3schools? Commented Jun 22, 2013 at 0:53
  • its just the code I have that works if on the page aside from being called by the jquery... if there'a a different way to get thet iframe loaded WITH the variables from the rest of the javascript! I'm fine with it, I just can't find any other way that works? Commented Jun 22, 2013 at 1:17

1 Answer 1

1

Just use append

$('body').append("<iframe height='1' width='1' frameborder='0' scrolling='no' src='https://www.emjcd.com/tags/c?containerTagId=49296&ITEM1="+skulist+"&AMT1="+pricelist+"&QTY1="+quantitylist+"&CID=10000171&OID=$(OrderNo)&TYPE=362565438&CURRENCY=USD' name='cj_conversion'></iframe>");
Sign up to request clarification or add additional context in comments.

3 Comments

when I do that, it doesnt "run" the variables in that iframe that are part of the javascript above where I have document write now.
@CVP did you replace the document.write line with this one
I didnt because the document.write is in my javascript, and that is a jquery? can I do that, would it work... I will try it...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.