View Full Version : 2 body tags

Mar 16th, 2007, 05:18 PM
A ppc optimising company we're using have given me some tracking code to include on our "thank you for buying" page.
This code includes a body tag with an onload attribute. And they recommend putting it just before the closing body tag of the document. So the document then has 2 body tags (There's no frames involved).

I'm pretty sure this is invalid html. Am i right? and are there any practical implications of this?

Mar 16th, 2007, 05:45 PM
Yes, I think they don't want you to put the body tag in there. You just need to copy the onload attribute/event handler into your body tag. And the actual tracking code goes right before the closing body tag of your page:

<body onload="dosomething();">
bla bla
<!-- tracking code -->
<script src="Ö"></script>

Mar 16th, 2007, 05:55 PM
yes, that's what i figured, but they're insisting that the extra body tag goes in.

Mar 16th, 2007, 06:10 PM
The onload event handler is triggered when the page (i.e. the body) has completely loaded. Therefore it isn't necessary to add another body tag at the bottom of the actual body.
Show me the code you're supposed to put in there please (you can encrypt any sensitive data but the general look should stay to figure it out).

Mar 16th, 2007, 06:24 PM
This is what they want me to paste just before the closing body tag:

<body onLoad="javascript:__utmSetTrans()">

<form style="display:none;" name="utmform">
<textarea id="utmtrans"> UTM:T|34535||6990.00|||London||UK
UTM:I|34535|23789|Life Fitness 9500 Treadmill|Treadmills|2995.00|1 UTM:I|34535|23790| Life Fitness 9600 Treadmill|Treadmills|3995.00|1

Now this is clearly invalid html, but are there any actual implications of this? They assure me that the tracking itself works.

Mar 16th, 2007, 10:21 PM
It will certainly break the page in some browsers that ignore invalid tags such as a seconf body tag.

Dump the extra body tag and just add the following line into a script in the head of your page:


Mar 16th, 2007, 10:30 PM
yeah that's what I plan to do. I just wanted another opinion on how much of a bad practice it is before I start altering someone elses code.


Mar 17th, 2007, 03:03 AM
Oh yeah, Googleís e-commerce trackingÖ I had to deal with that too, recently. The thing is that all this webmaster/marketing stuff by Google sounds so damn complicated! They have some kind of phrasing that always makes you think whether you have understood that right now (at least for me). :rolleyes:

However, Google is pretty clear in this case:

Next, somewhere in the receipt below the tracking code, the following lines need to be written by your engine. Everything in brackets should be replaced by actual values, as described in the Parameter Reference, below.

<form style="display:none;" name="utmform">
<textarea id="utmtrans">UTM:T|[order-id]|[affiliation]|
[total]|[tax]| [shipping]|[city]|[state]|[country] UTM:I|[order-id]|[sku/code]|[productname]|[category]|[price]|
[quantity] </textarea>

Finally, the utmSetTrans function must be called after the form is submitted in order to record the transaction. This can be most easily accomplished through a body onLoad event within the opening <body> tag:

<body onLoad="javascript:__utmSetTrans()">

If you don't have the ability to edit the body tag, you can call the utmSetTrans function within a separate script tag as long as you ensure that the function is called after the form:

<script type="text/javascript">

They don't say that you have to add the body tag at the bottom, just the tracking code. And then you put an onload event handler in the body tag (or alternatively at the bottom at its own.

And actually they give invalid JavaScript code because the javascript: is absolutely not necessary. A simple onload="__utmSetTrans();" is doing fine. Better is, as felgall stated, an onload event in the head section (or an external script):

<script type="application/javascript">
window.onload = __utmSetTrans;

Mar 17th, 2007, 07:19 PM
I'm pretty sure this is invalid html. Am i right?Having more than one body element is definitely incorrect (X)HTML.

and are there any practical implications of this?

If you use the body element as a styling anchor, itís possible that the element would styled twice. You may also have trouble targeting elements using the DOM if there are multiple such elements. Also, as mentioned, some browsers may also strip either copy, including the copy you require, as an error-handling mechanism. I havenít tested this, however, so I donít know which browsers do what.

And actually they give invalid JavaScript code because the javascript: is absolutely not necessary.Yes, the correct way to specify that event attributes contain JavaScript is to use a meta element or HTTP header:

<meta http-equiv="Content-Script-Type" content="text/javascript">

Content-Script-Type: text/javascript

Mar 17th, 2007, 08:42 PM
Whatís the current state of affairs with application/javascript? Is IE supporting it now?

Mar 17th, 2007, 10:50 PM
Whatís the current state of affairs with application/javascript? Is IE supporting it now?It doesnít look like it. In Internet Explorer versions 6 and 7, I tested application/javascript and application/ecmascript in the type attribute; in both cases, the script failed. After shifting the load event to an onload attribute and specifying those media types using a Content-Script-Type meta element, the script continued to work. I suspect that Internet Explorer ignores that element altogether. I didnít test the HTTP header method.