img没有src =(?!) [英] img without src= (?!)

查看:93
本文介绍了img没有src =(?!)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



由于其他一些原因,我正在查看Google

响应页面的来源(顺便说一下,它包含了一些可怕的SGML相关的
语法错误),并且有点惊讶地发现一些< img>标签用

没有src =属性。它们还出现在Mozilla的View-> Page

Info-> Media显示中,因为它们具有Type" Image"但是地址

列是空的。


他们像这样使用它们:


< td height = 7>< img width = 1 height = 1 alt ="">< / td>


和/或这个(语法无效但不同原因):


< td bgcolor =#3366cc>< img width = 1 height = 1 alt ="">


团队的想法是什么?


好​​的,我已经知道诉诸< td ...>& nbsp;< / td>在过去,

但我不认为我真的想这样做。

解决方案

Alan J. Flavell写道:


由于其他一些原因,我正在查看Google
响应页面的来源(顺便提一下包含一些可怕的与SGML相关的语法错误),


谷歌从来没有过多地关注他们制作的HTML(考虑到他们解析,这是多么奇怪如此多的HTML为生活 - 然后

再次,也许他们解析的所有HTML都说服了它们一切都很糟糕

无论如何)。

Google的HTML混乱的例外是Blogger.com,它试一试

(尽管上次我检查时它并没有验证......它们是

使用XHTML doctype)。

他们像这样使用它们:

< td height = 7>< img width = 1 height = 1 alt ="">< / td>

和/或s(语法无效,但原因不同):

< td bgcolor =#3366cc>< img width = 1 height = 1 alt ="">




好​​的,我相信*他们会以某种方式使用它来跟踪点击次数。注意

JavaScript函数ga()在每个搜索结果页面上。我刚刚在这个问题上写了

,但是他们改变了他们的功能。

< http://blog.outer-court.com/archive/...#1087207954423

88035>


无论他们做什么,我都确定每个小标签都意味着
流量的千兆字节(?)。我错了。


-

Google Blogoscoped
http://blog.outer-court.com


" Alan J. Flavell" < FL ***** @ ph.gla.ac.uk>写道:

- - 我 - - 有点惊讶找到一些< img>
没有src =属性的标签。


有趣。原则上,如果存在alt属性,我们是否应该说这些元素具有良好的定义渲染?毕竟,由于

没有要显示的图像,浏览器必须按规格渲染alt属性的值。另一方面,即使在语法层面(DTD),src属性也需要

,所以严格来说

规范并没有说明会发生什么 - 文档有误,

和错误处理(如果有的话)取决于浏览器。

< td height = 7>< img width = 1 height = 1 alt ="">< / td>


明显的目的是确保浏览器不会将单元格视为空白(这会导致一些未经考虑的效果,如抑制

背景颜色)。

好​​的,我已经知道诉诸于< td ...>& nbsp;< / td>在过去,
但我不认为我真的想这样做。




它的缺点是细胞不能变得任意小,

,因为不间断空间被视为一个字符,与当前字体中的其他字符占据相同的

高度。


通常的技巧是使用带有src属性的img元素,将

指向透明的单像素GIF图像。我没有看到任何好处,除了保存一点点b
键入或复制之外,省略src属性会有什么好处。我不知道谷歌为什么选择使用hacks的草率方式




令人惊讶的是IE似乎对待< img width = 1高度= 1 alt ="">

不显示任何内容(或者只是使用一个像素间距)。

如果省略width和height属性,显示了

破碎图像的常用符号。如果属性值是足够的话,则会发生同样的情况。大。我得到宽度=10的符号但不适用于

width =" 9" (测试了几种不同的字体大小,所以我猜它不会

取决于字体大小)。


-

Yucca, http://www.cs.tut.fi/~jkorpela/

关于网页制作的网页: http://www.cs.tut.fi/~jkorpela/www.html


Alan J. Flavell写道:< blockquote class =post_quotes>由于其他一些原因,我正在查看Google
响应页面的来源(其中包含一些可怕的与SGML相关的语法错误),并且是一个有点惊讶地发现一些< img>
没有src =属性的标签。它们还出现在Mozilla的View-> Page
Info-> Media显示中,因为它们具有Type" Image"但是地址栏目是空的。

他们像这样使用它们:

< td height = 7>< img width = 1 height = 1 alt ="">< / td>


嗯......很有意思。 A / spacer gif /,没有* spacer.gif *!它是

绝对无效,需要src属性,如DTD中所述。


<!ATTLIST IMG

%attrs; - %coreattrs,%i18n,%events -

src%URI; #REQUIRED - 要嵌入的图像的URI -

...


尽管如此,奇怪的是他们确实决定包含所需的

alt属性??

团队的想法是什么?


这不是谷歌在他们的加价中犯下的最严重的暴行,但它是非常有趣的。我知道他们打破了书中的所有其他规则,例如

使用表格进行布局,使用blockquote进行缩进,未编码

&符号在URI中,标记在DOCTYPE上面和< HTML> (查看

缓存页面时)etca?|但这个对我来说是新的,我以前从未见过有人做过


好​​吧,我已经知道会诉诸< td ... >&安培; NBSP;< / TD>在过去,




好​​吧,如果数据表需要一个空单元格,那么可能会有合理的结构和语义原因来执行

虽然我会认为

只是使用< td>< / td>在那些情况下是可以接受的。

如果原因纯粹是表现性的,那么这是不可接受的。


有谁知道编辑的原因,比如Dreamweaver,包括一个

& nbsp;在默认的空单元格中?是否兼容

与较旧的UAs或其他东西?


-

Lachlan Hunt
http://www.lachy.id.au/


请将所有垃圾邮件发送至ab***@127.0.0.1

谢谢。



For quite some other reason, I was looking at the source of a Google
response page (which by the way contains some horrible SGML-related
syntax errors), and was a bit surprised to find some <img> tags with
no src= attribute. They also show up in Mozilla''s View->Page
Info->Media display, in that they have Type "Image" but the "Address"
column is empty.

They use them like this:

<td height=7><img width=1 height=1 alt=""></td>

and/or this (invalid syntax but for a different reason):

<td bgcolor=#3366cc><img width=1 height=1 alt="">

What do the team think?

OK, I have been known to resort to <td ...>&nbsp;</td> in the past,
but I don''t think I''d really want to do that.

解决方案

Alan J. Flavell wrote:


For quite some other reason, I was looking at the source of a Google
response page (which by the way contains some horrible SGML-related
syntax errors),
Google never paid much attention to the HTML they produce (which is
somehow weird considering they parse so much HTML for a living -- then
again, maybe all the HTML they parse convinced them it''s all a mess
anyway).
Exception to Google''s HTML mess is Blogger.com, which at gives it a try
(though it didn''t validate throughout last time I checked... they are
using an XHTML doctype).

They use them like this:

<td height=7><img width=1 height=1 alt=""></td>

and/or this (invalid syntax but for a different reason):

<td bgcolor=#3366cc><img width=1 height=1 alt="">

What do the team think?



OK, I *believe* they somehow use this to track clicks. Note the
JavaScript function "ga()" on top of every search result page. I wrote
something on the issue a while ago but they changed their functions.
<http://blog.outer-court.com/archive/...#1087207954423
88035>

Whatever they do I''m certain every little tag means gigabytes (?) of
traffic. I could be wrong.

--
Google Blogoscoped
http://blog.outer-court.com


"Alan J. Flavell" <fl*****@ph.gla.ac.uk> wrote:

- - I - - was a bit surprised to find some <img> tags with
no src= attribute.
Interesting. In principle, should we say that such elements have well-
defined rendering, if an alt attribute is present? After all, since there
is no image to be shown, a browser must, by the specifications, render
the value of the alt attribute. On the other hand, the src attribute is
required even at the syntactic level (the DTD), so strictly speaking the
specifications don''t say what should happen - the document is in error,
and error processing (if any) is up to the browser.
<td height=7><img width=1 height=1 alt=""></td>
The apparent purpose is to make sure browsers don''t treat the cell as
empty (which would cause some undesidered effect, like suppression of
background color).
OK, I have been known to resort to <td ...>&nbsp;</td> in the past,
but I don''t think I''d really want to do that.



And it has the drawback that the cell cannot become arbitrarily small,
since the no-break space is treated as a character, occupying the same
height as other characters in the current font.

The usual trick is to use an img element with a src attribute that points
to a transparent single-pixel GIF image. I don''t see any benefits that
the omission of an src attribute would have, apart from saving a little
typing or copying. I have no idea why Google has chosen the sloppy way of
using hacks.

It is surprising that IE seems to treat an <img width=1 height=1 alt="">
by not displaying anything (or perhaps just using a one pixel spacing).
If the width and height attributes are omitted, the usual symbol for
broken image is shown. The same happens if the attribute values are
"sufficiently" large. I get that symbol for width="10" but not for
width="9" (tested with a few different font sizes, so I guess it does not
depend on font size).

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html


Alan J. Flavell wrote:

For quite some other reason, I was looking at the source of a Google
response page (which by the way contains some horrible SGML-related
syntax errors), and was a bit surprised to find some <img> tags with
no src= attribute. They also show up in Mozilla''s View->Page
Info->Media display, in that they have Type "Image" but the "Address"
column is empty.

They use them like this:

<td height=7><img width=1 height=1 alt=""></td>
Hmmm... Interesting. A /spacer gif/, without the *spacer.gif*! It''s
definitely invalid, the src attributes is required, as stated in the DTD.

<!ATTLIST IMG
%attrs; -- %coreattrs, %i18n, %events --
src %URI; #REQUIRED -- URI of image to embed --
...

Though, it''s strange that they actually decided to include the required
alt attributea??
What do the team think?
It''s not the worst atrocity Google has committed in their markup, but it
is quite funny. I knew they broke every other rule in the book, such as
using tables for layout, blockquote for indentation, unencoded
ampersands in URIs, markup above the DOCTYPE and <html> (when viewing
cached pages) etca?| but this one is new to me, I''ve never seen anyone do
that before.
OK, I have been known to resort to <td ...>&nbsp;</td> in the past,



Well, there can be legitimate structural and semantic reasons for doing
that if a table of data requires an empty cell, though I would have
thought that just using <td></td> would be acceptable in those cases.
If the reason is purely presentational, then it''s not acceptable.

Does anyone know the reason why editors, such as Dreamweaver, include an
&nbsp; in empty cells like that by default? Is it for compatibility
with older UAs or something?

--
Lachlan Hunt
http://www.lachy.id.au/

Please direct all spam to ab***@127.0.0.1
Thank you.


这篇关于img没有src =(?!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆