5568 sujets

Sémantique web et HTML

Jusqu'à présent je m'orientais vers du code propre, mais.. hum j'ignorais que le js était aussi concerné par les validateurs.

Là ca fait .C.. parce que, bon, je ne vois pas trop l'intérêt .
D'autant que, évidemment, c'est un script chopé pour afficher l'heure, et il pourri ma validation avec une douzaine d'erreurs.

A part le virer , comment k'c ty ky fo faire ??

Merci

le js là :



<script language="JavaScript">// Kaosweaver Live Clock Start

function class_clock(f,s,c,b,w,h,d) { // Copyright 2002 by Kaosweaver, All rights reserved

this.b=b;this.w=w;this.h=h;this.d=d;

this.o='<font style="color:'+c+'; font-family:'+f+'; font-size:'+s+'pt;">';

}

var clock=new class_clock("Geneva, Arial, Helvetica, sans-serif","8","#FFCC33","#000000","70",1,1)

d=document

if (d.all || d.getElementById) {d.write('<span id="activeClock" style="width:'+clock.w+'px; background-color:'+clock.b+'"></span>'); }

else if (d.layers) {d.write('<ilayer bgcolor="'+clock.b+'" id="wrapClock"><layer width="'+clock.w+'" id="activeClock"></layer></ilayer>'); }

else {KW_doClock(1);}

function KW_doClock(a) { // Copyright 2002 by Kaosweaver, All rights reserved

d=document;t=new Date();p="";dClock=""; if (d.layers) d.wrapClock.visibility="show";

h=t.getHours();m=t.getMinutes();s=t.getSeconds();if (clock.h)

{p=(h>12)?"pm":"am";h=(h>24)?h-24:h;h=(h==0)?0:h;}if (clock.d)

{m=(m<=9)?"0"+m:m; s=(s<=9)?"0"+s:s;} dClock = clock.o+h+':'+m+':'+s+' </font>';

if (a) {d.write(dClock);}if (d.layers) {wc = document.wrapClock;lc = wc.document.activeClock;

lc.document.write(dClock);lc.document.close();

} else if (d.all) { activeClock.innerHTML = dClock;

} else if (d.getElementById) {d.getElementById("activeClock").innerHTML = dClock;}

if (!a) setTimeout("KW_doClock()",1000);

}

// Kaosweaver Live Clock End</script>
[#]
Modifié par elz64 (10 Jul 2006 - 18:49)
L'attribut language est obsolète; il fait le remplacer par type="text/javascript". De plus, n'oublie pas de placer ton code Javascript en commentaire HTML (au cas où) :
<script type="text/javascript'>
//<!--

(...)

//-->
</script>
Merci,


Mais, hum au de la 1ere ligne ca tombe comme des mouches :


 Below are the results of checking this document for XML well-formedness and validity.

   1. Warning Line 75 column 2: character "<" is the first character of a delimiter but occurred as data.

      //<!--

      This message may appear in several cases:
          * You tried to include the "<" character in your page: you should escape it as "&lt;"
          * You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
          * Another possibility is that you forgot to close quotes in a previous tag.

      &#9993;
   2. Error Line 79 column 57: an attribute value literal can occur in an attribute specification list only after a VI delimiter.

      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

      Have you forgotten the "equal" sign marking the separation between the attribute and its declared value? Typical syntax is attribute="value".

      &#9993;
   3. Warning Line 79 column 59: character "&" is the first character of a delimiter but occurred as data.

      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

      This message may appear in several cases:
          * You tried to include the "<" character in your page: you should escape it as "&lt;"
          * You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
          * Another possibility is that you forgot to close quotes in a previous tag.

      &#9993;
   4. Warning Line 79 column 60: character "&" is the first character of a delimiter but occurred as data.

      if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {

      This message may appear in several cases:
          * You tried to include the "<" character in your page: you should escape it as "&lt;"
          * You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
          * Another possibility is that you forgot to close quotes in a previous tag.

      &#9993;
   5. Error Line 153 column 29: required attribute "type" not specified.

      <script language="JavaScript">

      The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.

      Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.

      &#9993;
   6. Error Line 159 column 29: required attribute "type" not specified.

      <script language="JavaScript">// Kaosweaver Live Clock Start

      The attribute given above is required for an element that you've used, but you have omitted it. For instance, in most HTML and XHTML document types the "type" attribute is required on the "script" element and the "alt" attribute is required for the "img" element.

      Typical values for type are type="text/css" for <style> and type="text/javascript" for <script>.

      &#9993;
   7. Error Line 165 column 72: document type does not allow element "font" here.

      ...'+c+'; font-family:'+f+'; font-size:'+s+'pt;">';

      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).

      &#9993;
   8. Error Line 175 column 45: there is no attribute "bgcolor".

      ...(d.layers) {d.write('<ilayer bgcolor="'+clock.b+'" id="wrapClock"><layer widt

      You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

      This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

      How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

      &#9993;
   9. Error Line 175 column 62: there is no attribute "id".

      ...te('<ilayer bgcolor="'+clock.b+'" id="wrapClock"><layer width="'+clock.w+'" i

      You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

      This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

      How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

      &#9993;
  10. Error Line 175 column 73: element "ilayer" undefined.

      ... bgcolor="'+clock.b+'" id="wrapClock"><layer width="'+clock.w+'" id="activeCl

      You have used the element named above in your document, but the document type you are using does not define an element of that name. This error is often caused by:
          * incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the "<frameset>" element),
          * by using vendor proprietary extensions such as "<spacer>" or "<marquee>" (this is usually fixed by using CSS to achieve the desired effect instead).
          * by using upper-case tags in XHTML (in XHTML attributes and elements must be all lower-case.

      &#9993;
  11. Error Line 175 column 87: there is no attribute "width".

      ...ock.b+'" id="wrapClock"><layer width="'+clock.w+'" id="activeClock"></layer><

      You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

      This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

      How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

      &#9993;
  12. Error Line 175 column 104: there is no attribute "id".

      ...Clock"><layer width="'+clock.w+'" id="activeClock"></layer></ilayer>'); }

      You have used the attribute named above in your document, but the document type you are using does not support that attribute for this element. This error is often caused by incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Transitional" document type to get the "target" attribute), or by using vendor proprietary extensions such as "marginheight" (this is usually fixed by using CSS to achieve the desired effect instead).

      This error may also result if the element itself is not supported in the document type you are using, as an undefined element will have no supported attributes; in this case, see the element-undefined error message for further information.

      How to fix: check the spelling and case of the element and attribute, (Remember XHTML is all lower-case) and/or check that they are both allowed in the chosen document type, and/or use CSS instead of this attribute.

      &#9993;
  13. Error Line 175 column 117: element "layer" undefined.

      ... width="'+clock.w+'" id="activeClock"></layer></ilayer>'); }

      You have used the element named above in your document, but the document type you are using does not define an element of that name. This error is often caused by:
          * incorrect use of the "Strict" document type with a document that uses frames (e.g. you must use the "Frameset" document type to get the "<frameset>" element),
          * by using vendor proprietary extensions such as "<spacer>" or "<marquee>" (this is usually fixed by using CSS to achieve the desired effect instead).
          * by using upper-case tags in XHTML (in XHTML attributes and elements must be all lower-case.

      &#9993;
  14. Warning Line 187 column 5: character "<" is the first character of a delimiter but occurred as data.

      {m=(m<=9)?"0"+m:m; s=(s<=9)?"0"+s:s;} dClock = clock.o+h+':'+m+':'+s+' </font>';

      This message may appear in several cases:
          * You tried to include the "<" character in your page: you should escape it as "&lt;"
          * You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
          * Another possibility is that you forgot to close quotes in a previous tag.

      &#9993;
  15. Warning Line 187 column 23: character "<" is the first character of a delimiter but occurred as data.

      {m=(m<=9)?"0"+m:m; s=(s<=9)?"0"+s:s;} dClock = clock.o+h+':'+m+':'+s+' </font>';

      This message may appear in several cases:
          * You tried to include the "<" character in your page: you should escape it as "&lt;"
          * You used an unescaped ampersand "&": this may be valid in some contexts, but it is recommended to use "&amp;", which is always safe.
          * Another possibility is that you forgot to close quotes in a previous tag.



Smiley bawling
Il faud que tu mette des balises de comentaires autour de ton code javascript car les navigateurs qui ne gèrent pas le javascript ne le prendront pas en compte et sans balises de commentaire il affichera le script.
phnx` a écrit :
Il faud que tu mette des balises de comentaires autour de ton code javascript car les navigateurs qui ne gèrent pas le javascript ne le prendront pas en compte et sans balises de commentaire il affichera le script.


C'est d'ailleurs ce que j'ai indiqué dans mon extrait de code...
Gilles a écrit :


C'est d'ailleurs ce que j'ai indiqué dans mon extrait de code...


Oui mais comme il ne l'avait pas fait j'ai voulu lui expliquer pourquoi c'était important de le faire Smiley smile