Travis Heeter
Travis Heeter

Reputation: 14074

Appending a tracking script with jQuery

I have this action tag that needs to appear on the page after a form submission:

<script>document.write('<s' + 'cript language="JavaScript" src="http://view.atdmt.com/jaction/***"></s' + 'cript>')</script><noscript><iframe src="http://view.atdmt.com/iaction/***" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe></noscript>

When I add this directly to the header, it shows up, and seems to work, however, when I try to add this with jQuery I get "Transferring data from view.atdmt.com" and a never-ending blank loading screen. This is my jQuery (If you run this in your console, you can see what I'm talking about):

$("head").append('<script>document.write(\'<s\' + \'cript language="JavaScript" src="http://view.atdmt.com/jaction/***"></s\' + \'cript>\')</script>' + '<noscript><iframe src="http://view.atdmt.com/iaction/***" width="1" height="1" frameborder="0" scrolling="No" marginheight="0" marginwidth="0" topmargin="0" leftmargin="0"></iframe></noscript>');

Upvotes: 0

Views: 184

Answers (1)

AJak
AJak

Reputation: 3873

Your using document.write in your jQuery code not sure why. Appending it adds it to your page.

Having something like the following should work

$("head").append('<script type="text/javascript" src="http://view.atdmt.com/jaction/***" /></script>');

Also, your no script tag is generated by javascript so it will never be rendered in the case of javascript being disabled.

Upvotes: 1

Related Questions