17

So a lead tracking company needs a link to fire and it was in the head tag...will it fire.

<head>
    <img width=1 height=1 src='http://track.searchignite.com/si/CM/Tracking/TransactionTracking.aspx?siclientid=4426&DetailDescription=935626&transactionamount=1&SICustTransType=19172&jscript=0&x10=goog&x9=1&x8=935626&x7=777+665-9999&x6=jones&x5=matt&x4=&x3=Camarillo&x2=Oxnard%2C+CA+Metro+Area&x1=Hidden+Springs&n1=Austin--Bedroom--austin_1_bedroom_apartments-P'>
</head>
Matt Elhotiby
  • 43,028
  • 85
  • 218
  • 321

11 Answers11

16

It shouldn't. The spec says:

User agents do not generally render elements that appear in the HEAD as content.

See the spec

But browsers can do anything they want to.

Added:

It's a loose area in the spec. Eg a browser could:

  • Render the element
  • Ignore the element
  • Load the image from its server but not render it
  • Or something else

... and the browser would be compliant.

So see what your favorite browsers do and then use the info as you wish...

Larry K
  • 47,808
  • 15
  • 87
  • 140
5

Yes. I tested in FireFox and Chrome and it was requested.

Adam
  • 43,763
  • 16
  • 104
  • 144
5

That would depend on the browser. The code is incorrect, and there is no standard for how to handle incorrect code, so it's up to each browser to try to make any sense of it.

I think that most browsers would change to a tag soup mode, and show whatever they can, but some browsers might ignore the image instead.

There is also the matter what the incorrect code does to the rest of the page. If the browser changes how the code is parsed, it may have negative effects on the code that is correct.

Guffa
  • 687,336
  • 108
  • 737
  • 1,005
4

Yes, the browser will attempt to load the img resource, but for reasons that aren't immediately obvious.

Assuming this is served as text/html, when the browser's parser sees the <img> element it will believe that it is encountering displayable content and simply infer the </head> and <body> tags (remember, these are optional in HTML), so the <img> is not actually in the head element, but in the body element.

If you use firebug, or another means of inspecting the DOM such as http://software.hixie.ch/utilities/js/live-dom-viewer/, you can see for yourself that this is the case.

Since the img is in body, the browser doesn't see it as different from any normal <img> element.

Alohci
  • 78,296
  • 16
  • 112
  • 156
2

Web browsers will indeed load the image. I suspect that the placement of it in the head of the document is because the src attribute doesn't load an actual image, so it would appear as a broken image in the web page itself. Since it's in the head, it will be called but not rendered on the page.

In effect, that acts like an asynchronous script call, because the browser will perform a GET request for that image's src attribute's URL while loading the page.

Tim S. Van Haren
  • 8,861
  • 2
  • 30
  • 34
2

Instead of setting width=1 height=1 I would set style="display:none" to prevent it from rendering and affecting layout.

All browsers will request the image in the header even with display:none.

I have checked it on:

  • MS Edge: 13
  • IE: 8, 9, 10 and 11
  • Safari: 9 and 6
  • FF: 25, 47 and 49
  • Chromium: 51
Oscar
  • 915
  • 10
  • 15
1

Most modern browsers will move the head and body up to leave any visible content inside the body. (You can see that in the inspector). It seems so reliable that it will be at least loaded, that Google uses it as a pixel tracking system inside a noscript tag, all inside the head (where they recommend to place the whole code, along with the script) in case javascript is not supported.

sergio
  • 997
  • 1
  • 11
  • 15
1

Most browsers don't bother about the rules, so it will work. But if you want to be standards compliant, you shouldn't do this. (At least in XHTML, it is invalid to place an <img> tag within <head>.)

casablanca
  • 69,683
  • 7
  • 133
  • 150
1

Technically yes.. but its much better to just put it in an HTML / JS call..

HTML

<body onload="triggerLink('4426');">

JAVASCRIPT

function triggerLink(var1){
    var receiveReq = getXmlHttpRequestObjectShipping();
    var url= 'http://track.searchignite.com/si/CM/Tracking/TransactionTracking.aspx?siclientid=' + var1;

    if (receiveReq.readyState == 4 || receiveReq.readyState == 0) {
        receiveReq.open("POST", url, true);
        receiveReq.onreadystatechange = handleLink; 
        receiveReq.send(null);
    }
}
function handleLink(){
    //Do This when request finished
}

You can add variables to the "tiggerLink" function as well to pass the rest of your URL parameters.

Dutchie432
  • 28,798
  • 20
  • 92
  • 109
0

I suggest using a <script> tag instead of an <img> tag. Then there is no question whether a browser will request the url. Just be sure it doesn't return anything that could cause a script error.

Ray
  • 21,485
  • 5
  • 48
  • 64
0

I would be more inclined to use a link to and specify it as stylesheet:

<link rel="stylesheet" type="text/css" src="http://track.searchignite.com/si/CM/Tracking/TransactionTracking.aspx?siclientid=4426&DetailDescription=935626&transactionamount=1&SICustTransType=19172&jscript=0&x10=goog&x9=1&x8=935626&x7=777+665-9999&x6=jones&x5=matt&x4=&x3=Camarillo&x2=Oxnard%2C+CA+Metro+Area&x1=Hidden+Springs&n1=Austin--Bedroom--austin_1_bedroom_apartments-P">

All should be OK if TransactionTracking.aspx returns empty content.

Sinan Ünür
  • 116,958
  • 15
  • 196
  • 339