Answers
Apr 12, 2007 - 04:54 AM
have u tried this, put your javascript in its own .js file then reference it in your xhtml document
Apr 13, 2007 - 12:42 AM
It would propably involve putting it in
Obviously I can put it in an external .js file, but that's not the question :-)
Jakob
Apr 16, 2007 - 04:16 AM
Right, it seems your very close on the mark with using the character data tags
How have you tried doing this in code?
eg
<br>/*<![CDATA[*/ <br> document.write('Hello World!'); <br>/*]]>*/ <br>
but the wiki does say not to use document.write, instead try to use node creation methods
http://en.wikibooks.org/wiki/XML_-_Ma...
May 19, 2007 - 04:04 AM
sorry for being a bit late with my respond.
I did try your suggestion amongst other things.
Here are two other options:
1: Which uses // style javascript comments instead of /* ... */
<br>//<![CDATA[ <br>document.write('Hello World!'); <br>//]]> <br>
I suspect the result is exactly the same as nidhi's suggestion in all browsers
2: Which use of simple html style comments (and a javascript // comment):
<br><!-- <br>document.write('Hello World!'); <br>//-->> <br>
I've seen this method used and suggested somewhere - and sometimes in combination with CDATA tags, but I don't really understand why it works, and it's probably also a kind of legacy approach to hide javascript from incompatible browsers.
3: The 'catch-all' bulletproof approach
<br><!--//--><![CDATA[//><!-- <br>document.title = "Foo & Bar"; <br>//--><!]]> <br>
I suppose it'll work. But as the author states:
"Remember that the very concept of sending XHTML to be handled by an HTML engine is essentially a hack and cannot be done flawlessly."
Source: http://www.webdevout.net/articles/esc...
For me the first approach did the trick in the major browsers.
Thanks, nidhi
Jan 14, 2009 - 04:16 AM
<br>//<![CDATA[ <br>document.write('Hello World!'); <br>//]]> <br>
Explanation:
the non-xhtml part of the script has to be wrapped in tags in order to validate.
These tags, which are invalid javascript, are then commented out with // (which is still valid xhtml).
Dec 25, 2010 - 06:15 PM
Apr 11, 2011 - 03:11 AM



Add New Comment