W3C home > Mailing lists > Public > www-validator@w3.org > July 2007

Re: Ampersands in JavaScript

From: David Dorward <david@dorward.me.uk>
Date: Wed, 18 Jul 2007 20:21:24 +0100
Message-Id: <1A4B69E0-E155-4F3A-BEC6-0EF26C1F2D0F@dorward.me.uk>
Cc: <www-validator@w3.org>
To: Peter Laudy <p.laudy@stream-group.nl>

On 18 Jul 2007, at 10:37, Peter Laudy wrote:
> I'm developing a web page, where I compose a URL in JavaScript and  
> then
> send it to the server using an XmlHttpObject (like you would when  
> using
> AJAX). This means that the URL is not processed by an HTML parser.

The ampersand character is inline in the document, so it is parsed by  
whatever parses the document. Since your document is served as text/ 
html, that is an HTML parser.

> If I
> use the & sign to add parameters to this URL, the page does not
> validate. If I use &amp; the URL is not correct.

You are using XHTML and serving it as text/html, but not following  
the guidelines laid down in Appendix C of the XHTML 1.0 specification  
which explain how to write your XHTML in such a way as to be so close  
to HTML 4.01 that it can be parsed by HTML parsers (it also renders  
using XHTML pointless).

It is invalid when you use & because XHTML is different. It doesn't  
work when you use &amp; because HTML parsers can't cope with that  
particular difference.


David Dorward
Received on Wednesday, 18 July 2007 19:21:46 UTC

This archive was generated by hypermail 2.3.1 : Tuesday, 1 March 2016 14:17:52 UTC