& in links

M

Matthew

I just ran a HTML validator on one of my web sites. It said that the
following is invalid:
<A HREF="products.cfm?type=Specialty&id=8">
and should be written:
<A HREF="products.cfm?type=Specialty&amp;id=8">

Does anybody know how serious this is?
Also, I am considering putting the following line at the top of every page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

Will this affect the decision about &amp; in links?

Thanks in advance,

Matthew
 
S

Steve Pugh

Matthew said:
I just ran a HTML validator on one of my web sites. It said that the
following is invalid:
<A HREF="products.cfm?type=Specialty&id=8">
and should be written:
<A HREF="products.cfm?type=Specialty&amp;id=8">

Does anybody know how serious this is?

Do you want valid code or not? If you do then you should change it.
Also, I am considering putting the following line at the top of every page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

Will this affect the decision about &amp; in links?

No.

Steve
 
E

Eric B. Bednarz

Matthew said:
I just ran a HTML validator on one of my web sites. It said that the
following is invalid:
<A HREF="products.cfm?type=Specialty&id=8">

Try a reference to a declared entity, eg

and should be written:
<A HREF="products.cfm?type=Specialty&amp;id=8">

Does anybody know how serious this is?

If you try the above, you'll see that it is valid but perhaps not just
what you expected; this issue has been discussed until the cows came
home. Try Google.
Also, I am considering putting the following line at the top of every page:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

Fine. Why?
Will this affect the decision about &amp; in links?

No. Thanks to doctype sniffing bogosity it is not quite impossible that
UA behaviour might differ when parsing URI references with undeclared or
existing entities, though.
 
D

DU

Steve said:
Do you want valid code or not? If you do then you should change it.

I'd like to reply to this. I entirely agree with the purpose of writing
entirely valid code as much as possible (if not always) but...
I was once asked why+how not writing &amp; in an uri would affect a
webpage, would cause problems or bugs or anything and I couldn't come up
with an answer. It seems that almost no matter how you write an uri,
browsers succeed in overcoming this very very frequent validation error.
I am just wondering, like I was asked, how this error affects webpages
or affects browsers. There must be somewhere a problem caused by not
escaping ampersand characters and/or there must be a benefit somehwere
for escaping, converting ampersand characters into &amp;: so, what is it?

DU
 
S

Steve Pugh

DU said:
I'd like to reply to this. I entirely agree with the purpose of writing
entirely valid code as much as possible (if not always) but...
I was once asked why+how not writing &amp; in an uri would affect a
webpage, would cause problems or bugs or anything and I couldn't come up
with an answer. It seems that almost no matter how you write an uri,
browsers succeed in overcoming this very very frequent validation error.
I am just wondering, like I was asked, how this error affects webpages
or affects browsers. There must be somewhere a problem caused by not
escaping ampersand characters and/or there must be a benefit somehwere
for escaping, converting ampersand characters into &amp;: so, what is it?

What happens if the sequence following the & is a character entity
reference? The browser will convert that to the relevant character,
thus changing the URL.

<a href="script.cgi?id=234&prod=234&sect=234"> looks like a perfectly
sound URL but as &prod and &sect are both HTML 4 character entity
references it's actually a different URL.

Can you remember all the character entity references and avoid using
them as parameter names? Easier and safer to write &amp;.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,040
Latest member
papereejit

Latest Threads

Top