What is the difference between &
and &
?
Like in the code bellow, are both working in the same way?
<a href="mailto:EMAIL?subject=BLABLABLA&body=http://URL, SHORT DESCRIPTION"></a>
<a href="mailto:EMAIL?subject=BLABLABLA&body=http://URL, SHORT DESCRIPTION"></a>
In HTML5, they are equivalent in that example. Traditionally, in HTML, only &
was correct — but as with so many things, web developers blithely ignored this inconvenient rule and wrote bare ampersands everywhere. For their part, browsers just "did the right thing" and interpreted these ampersands as ampersands. HTML5 standardized this behavior, so now &
is allowed by itself as long as what goes afterward does not look like an entity reference.
&
is the html special character for &
, which has a special meaning as the sigial for html special characters. The fact that href="&"
works is a convenience granted by most browsers who are nice enough to properly deal with invalid HTML, but it is technically incorrect. You want to use &
because the entity will be converted into &
in the HTML code.
Consider if you used "
instead of &
. That would end the href
value and make the HTML incorrect, right? You want to use "
.
See: http://www.w3.org/html/wg/drafts/html/master/single-page.html#syntax-errors "Errors involving fragile syntax constructs" -- in fact it points out that using &
is okay if it's not followed by a named character reference, but there are many of those; ideally you would be escaping attribute input more or less automatically.
&
is the html entity (encoded form) for &
, used to describe an ampersand in languages where an ampersand actually means something, like XML.
HTML rendering tools, like the browser, will see &
in the source but render &
来源:https://stackoverflow.com/questions/15776556/whats-the-difference-between-and-amp-in-html5