1174 sujets

Accessibilité du Web

Bonjour,

Je ne parviens pas à mettre une portion de code valide au W3C.

Ce code affiche un lien dans un textarea, afin que le visiteur puisse le copier.

Mon code:

<form class="lien" action="" method="post">
       <p><textarea cols="50" rows="3"><a href="http://www.mon-site.fr" title="mon titre">Mon texte</a></textarea></p>
</form>


Message W3C:
a écrit :

Line 153, Column 89: document type does not allow element "a" here.

…://www.mon-site.fr" title="mon titre">Mon texte</a></textarea></p>

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


Quelqu'un voit t-il ce qui ne va pas ?
Est-ce valide d'afficher un lien dans un textarea ?

Merci d'avance.
Modifié par yann123 (02 Mar 2009 - 16:16)
On ne peut pas mettre un lien tel quel dans un textarea sans utiliser les entités pour < et >. De plus ta manière de faire n'est pas correcte : soit on fourni le lien de manière traditionnelle, du genre :

<p><a href="http://www.mon-site.fr" title="Lien vers mon site">Permalien</a></p>



soit on utilise :

<p class="permalien"><code>&lt;a href="http://www.mon-site.fr" &gt;http://www.mon-site.fr&lt/a&gt;</code></p>



Avec une css qui va bien... Smiley cligne
Modifié par Patidou (02 Mar 2009 - 12:59)
Patidou a écrit :
On ne peut pas mettre un lien tel quel dans un textarea sans utiliser les entités pour < et >. De plus ta manière de faire n'est pas correcte : soit on fourni le lien de manière traditionnelle, du genre :

<p><a href="http://www.mon-site.fr" title="Lien vers mon site">Permalien</a></p>



Ce code affiche un lien cliquable normal, ce que je veux c'est que l'internaute puisse copier le code du lien, donc pas bon.

Patidou a écrit :

soit on utilise :

<p class="permalien"><code><a href="http://www.mon-site.fr" >http://www.mon-site.fr</a></code></p>



Avec une css qui va bien... Smiley cligne


Ca me conviens pas mal, sauf que le validateur w3c me renvoi encore une erreur:



Line 151, Column 99: reference not terminated by REFC delimiter.

…ite.fr" >http://www.mon-site.fr</a></code></p>

If you meant to include an entity that starts with "&", then you should terminate it with ";". Another reason for this error message is that you inadvertently created an entity by failing to escape an "&" character just before this text.
J'ai fait ça sans prévisualiser, il manquait un point-virgule (come indiqué par le validateur), voici le code correct :

<p class="permalien"><code>&lt;a href="http://www.mon-site.fr" &gt;http://www.mon-site.fr&lt;/a&gt;</code></p>

Modifié par Patidou (02 Mar 2009 - 15:53)