Comunidad de diseño web y desarrollo en internet online

no me valida un link en una imágen =(

Citar            
MensajeEscrito el 17 Feb 2008 05:35 pm
hola a todos, creo que este es mi primer post :P

En fin, tengo un problema:
Estoy haciendo una web en la que se deben mostrar imágenes aleatorias con link a la misma imagen en grande.
Para lograr el random, generé una funcion en javascript que devuelve un numero random, y ese numero es usado como nombre de la imágen en cuestión:

Código :

nroImg = imgRand(27);
document.write('<a href="multimedia/images/'+nroImg+'.jpg" target="_blank"><img src="multimedia/images/thumbs/'+nroImg+'.jpg" alt="" /></a>');


anda perfecto, pero la cuestión es que no me valida el xhtml y no sé que es lo que estoy haciendo mal
(y soy una loca de la validación, no soporto tener una página inválida :P)


dice:

Line 182, Column 80: document type does not allow element "a" here.
…mages/'+nroImg+'.jpg" target="_blank"><img src="multimedia/images/thumbs/'+nr

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


uso XHTML 1.0 Transitional

y bueno, no entiendo cual es el problema :S
si pudieran darme una mano para guiarme se los agradeceré :)

saludos a todos!!

Por angel_eskarlata

68 de clabLevel



Genero:Femenino  

Baires City

opera
Citar            
MensajeEscrito el 17 Feb 2008 07:09 pm
El problema al parecer está en dónde ubicaste el js que genera la imagen con el enlace. (Quizá es porque está suelto en el <body>). Usualmente se soluciona si le agregas algún contenedor, como puede ser un div:

Código :

nroImg = imgRand(27);
document.write('<div><a href="multimedia/images/'+nroImg+'.jpg" target="_blank"><img src="multimedia/images/thumbs/'+nroImg+'.jpg" alt="" /></a></div>);

Igual no estoy muy seguro. Prueba y comenta.

Saludos.

Por eZakto

43 de clabLevel



Genero:Masculino  

Salta, Argentina.

firefox
Citar            
MensajeEscrito el 18 Feb 2008 02:19 am
gracias por la respuesta eZakto, pero no ha funcionado, al contrario, ahora me dice que lo que no valida es justamente el div :lol:

Line 182, Column 26: document type does not allow element "div" here.
document.write('<div><a href="multimedia/images/'+nroImg+'.jpg" target="_b


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



de todos modos el script ya estaba dentro de un div anterior que contiene la imágen y un título..

:S

este es el código completo de todo el div

Código :

<div id="imghoy">
<h1>Una foto al azar</h1>
<script language="javascript" type="text/javascript">
nroImg = imgRand(27);
document.write('<div><a href="multimedia/images/'+nroImg+'.jpg" target="_blank"><img src="multimedia/images/thumbs/'+nroImg+'.jpg" alt="Mat&iacute;as!" /></a></div>');
</script>
<p><small><a href="multimedia/img.htm">Ver todas las fotos!</a></small></p>
</div>


pensé que podía ser algún tag mal cerrado anteriormente, pero chekeé uno por uno y están todos con su cierre correspondiente, por eso me ha resultado tan raro este error de validación :S

Por angel_eskarlata

68 de clabLevel



Genero:Femenino  

Baires City

opera
Citar            
MensajeEscrito el 18 Feb 2008 02:47 am
Si no me equivoco, en xHTML, los <script> han de ir dentro del <head>, con lo que las sentencias "document.write", no son válidas.
Deberías probar entonces con un "document.getElelemtnById('ID').innerHTML", y meter el código generado, en el <div id="ID"> que contenía el script

Por El Oso Amoroso

Claber

1780 de clabLevel

6 tutoriales

 

Madrid, España, Europa, Eurasia, La Tierra, Sist.Solar, Vía Láctea, UNIVERSO

firefox
Citar            
MensajeEscrito el 18 Feb 2008 05:46 pm
Que molesto... Por qué no pruebas con php y ya? XD

Código :

<?php
$nroImg = rand(27);
echo '<a href="multimedia/images/'+$nroImg+'.jpg" target="_blank"><img src="multimedia/images/thumbs/'+$nroImg+'.jpg" alt="Mat&iacute;as!" /></a>';
?>


Y listo!! :P

Saludos.

Por eZakto

43 de clabLevel



Genero:Masculino  

Salta, Argentina.

firefox
Citar            
MensajeEscrito el 25 Feb 2008 04:28 am
si, al final lo terminé haciendo asi, es que recién estoy empezando con php y no se me había ocurrido :P
gracias igual! =D

Por angel_eskarlata

68 de clabLevel



Genero:Femenino  

Baires City

opera
Citar            
MensajeEscrito el 25 Feb 2008 05:15 pm
Igual el mío estaba mal, para concatenar tienes que usar ".", no "+".

Saludos.

Por eZakto

43 de clabLevel



Genero:Masculino  

Salta, Argentina.

firefox
Citar            
MensajeEscrito el 26 Feb 2008 02:16 am
tenés razón, no lo leí :P
igual lo que yo hice, como el nro lo saco de otra variable, fue directamente escribir todo el tag en html, y el nro sólo en un echo, asi que quedó

Código :

<a href="multimedia/images/<? echo $imgRand; ?>.jpg" target="_blank">
           <img src="multimedia/images/thumbs/<? echo $imgRand; ?>.jpg" />

bueno, es lo mismo xD

gracias de nuevo por la atención ^^

Por angel_eskarlata

68 de clabLevel



Genero:Femenino  

Baires City

opera
Citar            
MensajeEscrito el 26 Feb 2008 12:52 pm
Puedes ahorrarte el echo escribiéndolo así:

Código :

<a href="multimedia/images/<?=$imgRand?>.jpg" target="_blank">
           <img src="multimedia/images/thumbs/<?=$imgRand?>.jpg" />

Saludos.

Por eZakto

43 de clabLevel



Genero:Masculino  

Salta, Argentina.

firefox

 

Cristalab BabyBlue v4 + V4 © 2011 Cristalab
Powered by ClabEngines v4, HTML5, love and ponies.