JavaScript - Problemas con imagen en pop-up

 
Vista:

Problemas con imagen en pop-up

Publicado por Eduard (5 intervenciones) el 15/09/2005 09:39:37
Tengo un script que me abre una imagen en una ventana nueva, y adapta el tamaño de la ventana a la imagen. El script lo pongo mas abajo. El problema que teng es que debo clicar dos veces en la imagen: en el primer clic solo se abre una ventana muy grande, vacía; en el segundo se abre una ventana con la imagen y el tamaño correcto.
Alguien sabe como puedo arreglarlo?

<script type="text/javascript">
var win=null;
function mostrarimatge(url_imatge,titol){
var img = new Image();
img.src = url_imatge;
dreta=(screen.width-img.width)/2;
dalt=(screen.height-img.height)/2;
win=window.open('','','width='+img.width+',height='+img.height+',scrollbars=no,resizable=0,toolbar=0,left='+dreta+',top='+dalt+'');
win.document.write ('<html>\n');
win.document.write (' <head>\n');
win.document.write (' <title>'+titol+'<\/title>\n');
win.document.write (' <\/head>\n');
win.document.write (' <body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">\n');
win.document.write (' <img src="' + url_imatge + '" height='+img.height+' width='+img.width+'>\n');
win.document.write (' <\/body>\n');
win.document.write ('<\/html>\n');
}
</script>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder