[JS] Probleme de W3C

Statut
N'est pas ouverte pour d'autres réponses.

MbK_

Etudjant
Slt à tous,

Je suis entrain de retirer les erreurs pour valider mon code W3C. Mais j'apperçois qu'un grand nombre de mes erreurs sont dues à une fonction JS. J'ai essayé de la modifier pour supprimer les erreurs mais elle ne fonctionne plus à ce moment.

Cette fonction sert à faire une autoresize des popup pour l'ajuster à une image. La voici

Code:
function resizePopUp(monImage, monTitre){
	w = window.open('','chargement','width=5,height=5');
	w.document.write( "<html><head><title>"+monTitre+"</title>\n" );
	w.document.write( "<script language='JavaScript'>\n");
	w.document.write( "IE5=NN4=NN6=false;\n");
	w.document.write( "if(document.all)IE5=true;\n");
	w.document.write( "else if(document.getElementById)NN6=true;\n");
	w.document.write( "else if(document.layers)NN4=true;\n");
	w.document.write( "function autoSize() {\n");
	w.document.write( "if(IE5) self.resizeTo(document.images[0].width+10,document.images[0].height+31);\n");
	w.document.write( "else if(NN6) self.sizeToContent();\n");
	w.document.write( "else window.resizeTo(document.images[0].width,document.images[0].height+20);\n");
	w.document.write( "self.focus();\n");
	w.document.write( "}\n</scri");
	w.document.write( "pt>\n");
	w.document.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad='javascript:autoSize();'>" );
	w.document.write( "<a href='javascript:window.close();'><img src='"+monImage+"' border=0 alt='"+monTitre+"'></a>" );
    w.document.write( "</body></html>" );
	w.document.close();
}
Avez vous une idée pour remedier à ce problème?

Connaissez vous une fonction identique mais valide W3C?

Merci ;)
 

Bingo

Beer Addict
Quelqu'un qui valide son code, ce sera un plaisir de l'aider ! :D

Quelle est l'erreur donnée par le validateur ?
 
1er
OP
MbK_

MbK_

Etudjant
Line 69, column 58: end tag for element "TITLE" which is not open

w.document.write( "<html><head><title>"+monTitre+"</title>\n" );

The Validator found an end tag for the above element, but that element is not currently open. This is often caused by a leftover end tag from an element that was removed during editing, or by an implicitly closed element (if you have an error related to an element being used where it is not allowed, this is almost certainly the case). In the latter case this error will disappear as soon as you fix the original problem.

If this error occured in a script section of your document, you should probably read this FAQ entry.

✉

Line 80, column 29: delimiter """ invalid: only S separators and TAGC allowed here

w.document.write( "}\n</scri");

✉

Line 80, column 29: end tag for element "SCRI" which is not open

w.document.write( "}\n</scri");

✉

Line 82, column 26: end tag for "SCRIPT" omitted, but its declaration does not permit this

w.document.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginhe

✉

Line 29, column 1: start tag was here

<script type="text/javascript">

Line 82, column 44: there is no attribute "LEFTMARGIN"

...ment.write( "</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight

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.

✉

Line 82, column 56: there is no attribute "TOPMARGIN"

..."</head><body leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad='j

✉

Line 82, column 70: there is no attribute "MARGINWIDTH"

...leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 onLoad='javascript:auto

✉

Line 82, column 85: there is no attribute "MARGINHEIGHT"

...pmargin=0 marginwidth=0 marginheight=0 onLoad='javascript:autoSize();'>" );

✉

Line 84, column 37: character data is not allowed here

w.document.write( "</body></html>" );

You have used character data somewhere it is not permitted to appear. Mistakes that can cause this error include putting text directly in the body of the document without wrapping it in a container element (such as a <p>aragraph</p>) or forgetting to quote an attribute value (where characters such as "%" and "/" are common, but cannot appear without surrounding quotes).

EDIT : http://validator.w3.org/check?uri=www.friteries.net

c'est plus simple
 

Bingo

Beer Addict
Ah, ça me rassure !
C'est juste que le validateur interprête mal le html qui se trouve dans un javascript.
C'est expliqué plus précisément ici.
En gros, si tu veux éviter qu'il te donne ces lignes en erreur, à chaque fois que tu as une balise de fermeture (</qq chose>) dans une fonction .write, tu mets un backslash devant le slash et ça devrait passer (<\/qq chose>).
Mais ton html est valide, pas de problème.
 

sebge2

Elite
oui je rejoint sa conclusion ... parce que j'ai deja utilisé cette fonction elle va très bien ;)
 
1er
OP
MbK_

MbK_

Etudjant
haaa en effet, c'était bien l'antislashe.

Merci Bingo, hugues & sebge2 ^^


EDIT : encore un petit probleme mais moins grave :

la ligne que le W3C met comme indication d'ou se trouve l'erreur, c'est la ligne du code HTML généré pour l'affichage?

Si on travaille en PHP, c'est la page générée?
 

sebge2

Elite
MbK_ a dit:
haaa en effet, c'était bien l'antislashe.

Merci Bingo, hugues & sebge2 ^^


EDIT : encore un petit probleme mais moins grave :

la ligne que le W3C met comme indication d'ou se trouve l'erreur, c'est la ligne du code HTML généré pour l'affichage?

Si on travaille en PHP, c'est la page générée?
oui c'est le code source de la page html générée .... ;) ta console JS étant local et ton pc ne recevant que le code exécuté tu ne pourras jamais voir le code php a distance :wink:

assez clair ? dsl je suis un peu out :wink:
 
1er
OP
MbK_

MbK_

Etudjant
c'est bien ce qu'il me semblait,

mais j'avais des doutes pcq les lignes ne correspondent pas très bien..

merci en tout cas, mnt je suis valide :)
 
Statut
N'est pas ouverte pour d'autres réponses.
Haut