Forum Moderators: open
ive joined a banner exchange program and the javascript they game me isnt valid xhtml
which basically means my whole site has stopped being valid
any help would be appreciated
this is the original code
<!-- Japan Banner Exchange Begin -->
<center>
<script language="JavaScript">
document.write('<s'+'cript language="JavaScript" src="http://ad.XXXX.com/work.php?n=278&size=1&j=1&code='+new Date().getTime()+'"></s'+'cript>');
</script>
<NOSCRIPT>
<IFRAME SRC="http://ad.XXXX.com/work.php?n=278&size=1" width=477 height=60 marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></IFRAME>
</NOSCRIPT>
</center>
<!-- Japan Banner Exchange End --> and this is after i cleaned it up a bit
<!-- Japan Banner Exchange Begin -->
<center>
<script language="JavaScript" type="text/javascript">
document.write('<s'+'cript language="JavaScript" src="http://ad.XXXX.com/work.php?n=278&size=1&j=1&code='+new Date().getTime()+'"></s'+'cript>');
</script>
<noscript>
<iframe src="http://ad.XXXX.com/work.php?n=278&size=1" width="477" height="60" marginwidth="0" marginheight="0" frameborder="0" scrolling="no"></iframe>
</noscript>
</center>
<!-- Japan Banner Exchange End --> but there are three errors remaining and i just dont know what to do
#Line 23, column 18: an attribute specification must start with a name or name tokendocument.write('<s[U]'[/U]+'cript language="JavaScript" src="http://ad.XXXX.com/work.ph
Check for stray quotes or incomplete attribute definitions.
#Line 23, column 18: document type does not allow element "s" here
document.write('<s[U]'[/U]+'cript language="JavaScript" src="http://ad.XXXX.com/work.ph
The element named above was found in a context where it is not allowed. This could mean that you have incorrectly nested elements -- such as a "style" element in the "body" section instead of inside "head" -- or two elements that overlap (which is not allowed).
One common cause for this error is the use of XHTML syntax in HTML documents. Due to HTML's rules of implicitly closed elements, this error can create cascading effects. For instance, using XHTML's "self-closing" tags for "meta" and "link" in the "head" section of a HTML document may cause the parser to infer the end of the "head" section and the beginning of the "body" section (where "link" and "meta" are not allowed; hence the reported error).
#Line 23, column 144: delimiter "'" invalid: only S separators and TAGC allowed here
...amp;code='+new Date().getTime()+'></s[U]'[/U]+'cript>');
The second and third errors - well, take a closer look at them. Because of the way the code is written, it looks like you have an element <s> there - the start of the script tag. Clearly the validator has a problem with that, because it doesn't know it's meant to be a script tag. So ignore those 2 errors completely.
You should also encode any ampersands in the URLs. (So "&" should be written as "&".)
Also JavaScript in XHTML should be called from another file, not part of the page itself, unless there's no way round it.
<script> tags is (X)HTML - which it isn't. So the error is in the validator, not the document. Your best bet is to place the Javascript in an external file, as Hester has suggested: <script type="text/javascript" [b]src="/path/to/js-file.js"[/b]></script> The document will then be parsed correctly by the validator.
I thought document.write didn't exist in XHTML?
In pure XHTML served as
application/xhtml+xml, no, document.write isn't (and can't be) supported. But XHTML is almost always served as text/html and as such, it is merely seen by the browser as slightly broken HTML - and in HTML, you can use document.write with no problems. :)