html图像标记是否会在head标记中执行

时间:2022-11-19 14:43:56

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>

11 个解决方案

#1


14  

It shouldn't. The spec says:

它不应该。规范说:

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

用户代理通常不会将HEAD中出现的元素呈现为内容。

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...

所以,看看你最喜欢的浏览器做什么,然后根据你的意愿使用信息......

#2


5  

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

是。我在FireFox和Chrome中进行了测试,并且要求它。

#3


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.

还有一个问题是错误的代码对页面的其余部分做了什么。如果浏览器更改了代码的解析方式,则可能会对正确的代码产生负面影响。

#4


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.

Web浏览器确实会加载图像。我怀疑将它放在文档的头部是因为src属性没有加载实际图像,所以它在网页本身中显示为一个损坏的图像。因为它在头部,它将被调用但不在页面上呈现。

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.

实际上,这就像一个异步脚本调用,因为浏览器将在加载页面时对该图像的src属性的URL执行GET请求。

#5


2  

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

是的,浏览器将尝试加载img资源,但原因不是很明显。

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.

假设这是作为text / html提供的,当浏览器的解析器看到html图像标记是否会在head标记中执行元素时,它会认为它遇到了可显示的内容,只是推断出 和标签(记住,这些在HTML中是可选的) ,所以html图像标记是否会在head标记中执行实际上并不在head元素中,而是在body元素中。

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.

如果您使用firebug或其他检查DOM的方法,例如http://software.hixie.ch/utilities/js/live-dom-viewer/,您可以亲眼看到这种情况。

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

由于img在body中,浏览器看不到它与任何普通的html图像标记是否会在head标记中执行元素不同。

#6


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>.)

大多数浏览器都不关心规则,所以它会起作用。但如果你想要符合标准,你就不应该这样做。 (至少在XHTML中,在中放置html图像标记是否会在head标记中执行标签是无效的。)

#7


1  

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

技术上是的..但它更好地把它放在一个HTML / JS调用..

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.

您可以将变量添加到“tiggerLink”函数以传递其余的URL参数。

#8


1  

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

而不是设置width = 1 height = 1我将设置style =“display:none”以防止它渲染并影响布局。

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

即使使用display:none,所有浏览器也会在标题中请求图像。

I have checked it on:

我查了一下:

  • MS Edge: 13
  • MS Edge:13

  • IE: 8, 9, 10 and 11
  • IE:8,9,10和11

  • Safari: 9 and 6
  • Safari:9和6

  • FF: 25, 47 and 49
  • FF:25,47和49

  • Chromium: 51

#9


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.

我建议使用

#10


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.

如果TransactionTracking.aspx返回空内容,则一切正常。

#11


0  

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.

大多数现代浏览器会将头部和身体向上移动,以在身体内留下任何可见内容。 (你可以在检查员中看到)。看起来非常可靠,它至少会被加载,谷歌将它用作noscript标签内的像素跟踪系统,所有这些都在头部内部(他们建议将整个代码与脚本一起放置)以防javascript不是支持的。

#1


14  

It shouldn't. The spec says:

它不应该。规范说:

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

用户代理通常不会将HEAD中出现的元素呈现为内容。

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...

所以,看看你最喜欢的浏览器做什么,然后根据你的意愿使用信息......

#2


5  

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

是。我在FireFox和Chrome中进行了测试,并且要求它。

#3


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.

还有一个问题是错误的代码对页面的其余部分做了什么。如果浏览器更改了代码的解析方式,则可能会对正确的代码产生负面影响。

#4


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.

Web浏览器确实会加载图像。我怀疑将它放在文档的头部是因为src属性没有加载实际图像,所以它在网页本身中显示为一个损坏的图像。因为它在头部,它将被调用但不在页面上呈现。

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.

实际上,这就像一个异步脚本调用,因为浏览器将在加载页面时对该图像的src属性的URL执行GET请求。

#5


2  

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

是的,浏览器将尝试加载img资源,但原因不是很明显。

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.

假设这是作为text / html提供的,当浏览器的解析器看到html图像标记是否会在head标记中执行元素时,它会认为它遇到了可显示的内容,只是推断出 和标签(记住,这些在HTML中是可选的) ,所以html图像标记是否会在head标记中执行实际上并不在head元素中,而是在body元素中。

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.

如果您使用firebug或其他检查DOM的方法,例如http://software.hixie.ch/utilities/js/live-dom-viewer/,您可以亲眼看到这种情况。

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

由于img在body中,浏览器看不到它与任何普通的html图像标记是否会在head标记中执行元素不同。

#6


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>.)

大多数浏览器都不关心规则,所以它会起作用。但如果你想要符合标准,你就不应该这样做。 (至少在XHTML中,在中放置html图像标记是否会在head标记中执行标签是无效的。)

#7


1  

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

技术上是的..但它更好地把它放在一个HTML / JS调用..

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.

您可以将变量添加到“tiggerLink”函数以传递其余的URL参数。

#8


1  

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

而不是设置width = 1 height = 1我将设置style =“display:none”以防止它渲染并影响布局。

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

即使使用display:none,所有浏览器也会在标题中请求图像。

I have checked it on:

我查了一下:

  • MS Edge: 13
  • MS Edge:13

  • IE: 8, 9, 10 and 11
  • IE:8,9,10和11

  • Safari: 9 and 6
  • Safari:9和6

  • FF: 25, 47 and 49
  • FF:25,47和49

  • Chromium: 51

#9


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.

我建议使用

#10


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.

如果TransactionTracking.aspx返回空内容,则一切正常。

#11


0  

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.

大多数现代浏览器会将头部和身体向上移动,以在身体内留下任何可见内容。 (你可以在检查员中看到)。看起来非常可靠,它至少会被加载,谷歌将它用作noscript标签内的像素跟踪系统,所有这些都在头部内部(他们建议将整个代码与脚本一起放置)以防javascript不是支持的。