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

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 UTC