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

Re: Javascript within href reported as error if contains & or =

From: David Dorward <david@dorward.me.uk>
Date: Wed, 11 Apr 2007 23:13:50 +0100
Message-ID: <461D5D9E.8050200@dorward.me.uk>
To: Peter Jones <jonespm2@shaw.ca>
CC: www-validator@w3.org

Peter Jones wrote:

> The validator reports errors, like 'cannot generate system identifier
> for general entity "barney"' and 'reference not terminated by REFC
> delimiter' when code like the following is submitted.

> <a href="javascript:myFunc('fred&barney=flintstones');">Test</a>

Yes, that is because it is invalid.

> Checking within the href attribute should be turned off when it begins with 'javascript,
> unless you really are going to check it as javascript.

No, it shouldn't. The code is not "just JavaScript", it is "JavaScript
encoded in an HTML document" and ampersands should be represented by
entities as they have special meaning in HTML (inside <script> and
<style> elements is an exception as they are defined elements that
contain CDATA).

Additionally, the practice of using pseudo-URIs starting with
"javascript:" is frowned upon. See http://www.jibbering.com/faq/#FAQ4_24
for details.

-- 
David Dorward                               <http://dorward.me.uk/>
Received on Wednesday, 11 April 2007 22:14:27 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Wednesday, 25 April 2012 12:14:24 GMT