...

View Full Version : XHTML and scripting



Kennis
07-05-2002, 09:51 AM
I'm just getting to grips with XHTML standards at the moment. It's fairly straightforward making basic HTML compliant to XHTML but what are the specifications/rules for making sure that all scripts (javascript, DHTML, etc.) are compliant to XHTML? Is scripting handled differently or even accounted for?

Zvona
07-05-2002, 01:00 PM
Not really. XHTML is used for defining structure of a document, which won't directly affect on scripting. I've noticed minor style differences with CSS between HTML 4.01 DTD and XHTML 1.0 DTD.

jkd
07-05-2002, 06:09 PM
One thing to be careful about:

<script type="text/javascript">
if (something < bla) {
// ....
}
</script>

Suddenly your document becomes invalid. Because Javascript extensively uses the <, >, and & signs, you either need to replace all occurrences of them with:
&amp;lt; --> "<"
&amp;gt; --> ">"
&amp;amp; --> "&"

But since that will definitely cause issues with browsers not truely supporting XHTML, you put the entire script in a <![CDATA script contents ]]> section. Once again though you run into older browser support, which is finally solved by a little hack:

<script type="text/javascript">
<!--// <![CDATA
//script contents
// ]]> -->
</script>


Also, if you dynamically generate any content, be sure you generate valid markup. (Using W3C DOM methods automatically takes care of it for you, but be wary with innerHTML and the such.)

Alex Vincent
07-06-2002, 04:00 AM
Or you could always outsource your scripts...

<script language="JavaScript" type="text/javascript" src="myscript.js"></script>

That seems to be the easiest of all.

jkd
07-06-2002, 05:00 AM
Originally posted by Alex Vincent
Or you could always outsource your scripts...

<script language="JavaScript" type="text/javascript" src="myscript.js"></script>

That seems to be the easiest of all.

True, but can be inconvenient at times.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum