Howdy,
First off, I should say that I am jumping on posting this issue much quicker than I normally would - but I'm not really in a patient mood now, and I'm far from being a fan of anything the W3 has done.
Anyhow, I am in the process of going through a CMS I've built the past decade and cleaning up its markup so it validates (XHTML Strict).
I've run into a little hitch and was wondering if there is a simple solution, or if this is another one of the many restrictions XHTML seems to impose.
I understand the whole concept of encoding ampersands - that isn't news to me.
My problems lies within JavaScript which is directly placed within the XHTML markup, and doesn't reside in a JavaScript specific file.
For example, here is some JavaScript residing within the markup (which I understand to be valid):
<script type='text/javascript'>initializeRefresh('ajaxdata.php?type=my_status&u=x&mode=x&showmore=x', 15,'MyStatusMessagePane');</script>
... there I have NOT encoded the ampersands, because as context would dictate, ampersands shouldn't be encoded when in a JavaScript context - correct?
Well, the validator throws a fit over it and spits out many errors and warnings over this usage, despite being allowed to hold JavaScript within your markup.
So if I change the code to look more like:
<script type='text/javascript'>initializeRefresh('ajaxdata.php?type=my_status&u=x&mode=x&showmore=x', 15,'MyStatusMessagePane');</script>
... the validator DOESN'T complain, but the JavaScript code is broken, as the incorrect URL is parsed and loaded. Obviously, I know I could just go into the JavaScript function and replace encoded ampersands with the character itself, but this isn't a solution in my opinion, because it only hides the problem and doesn't address the cause.
This same situation occurs in a more common use of JavaScript like so:
<span onclick="window.location.href='http://example.com/page.php?id=x&somethig=x';">blah</span>
That code would fail validation, but function properly; yet if you encode the ampersand, it will validate, but won't work!
So, what's up here? I'll either slap myself for missing something so silly, or I'll add more fuel to my already roaring fire against W3. >_<
Surely there has got to be a practical approach here - to appease both ends - that I've just overlooked or haven't been aware of.
I appreciate any information any of you guys and gals may have!
Thanks for your time.