Ver Mensaje Individual
  #5 (permalink)  
Antiguo 23/08/2007, 09:15
Avatar de derkenuke
derkenuke
Colaborador
 
Fecha de Ingreso: octubre-2003
Ubicación: self.location.href
Mensajes: 2.665
Antigüedad: 20 años, 7 meses
Puntos: 45
Re: Como abrir nueva ventana del navegador???

Hola:

El script me ha funcionado correctamente. Lo que ocurre es que escribe contenido proporcionado automáticamente por http://convert.rss-to-javascript.com en el documento. Estos enlaces no contienen el atributo target, por lo que se abren en la misma ventana.

Lo que he hecho, es recorrer todos los enlaces de la capa roja (una vez cargado el documento) y aplicarles el atributo target.

Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
>
<
html xmlns="http://www.w3.org/1999/xhtml" xml:lang="es" lang="es">
<
head>
<
meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
<
meta name="Author" content="derkeNuke" />
<
title>Página nueva</title>
<
style type="text/css">
</
style>

<
script type="text/javascript">
function 
e(q,noBr) {
    
document.body.appendChilddocument.createTextNode(q) );
    if(!
noBrdocument.body.appendChilddocument.createElement("BR") );
}

var 
idContenedor="tengoEnlaces";
window.onload = function() {
    var 
enlaces document.getElementById(idContenedor).getElementsByTagName("a");
    
e("entro y hay "+enlaces.length+" enlaces.");
    for(var 
i=0i<enlaces.lengthi++) {
        
enlaces[i].target "_blank";
    }
}
</script>

</head>

<body>

<div style="background-color:red;" id="tengoEnlaces">
    <script type="text/javascript" src="http://convert.rss-to-javascript.com/?src=http%3A%2F%2Fwww.emol.com%2Frss20%2Frss.asp%3Fcanal%3D0">
    </script>
</div>
<noscript>
    Your browser does not support JavaScript. 
    <a title='RSS-to-JavaScript.com: Free RSS to JavaScript Converter' href="http://www.rss-to-javascript.com/?p=151,381&src=http%3A%2F%2Fwww.emol.com%2Frss20%2 Frss.asp%3Fcanal%3D0&as_html=1">Click to read the latest news</a>.
</noscript>
<a href="http://www.rss-to-javascript.com" target="_blank" title='RSS-to-JavaScript.com: Free RSS to JavaScript Converter'>
    <img src="http://www.rss-to-javascript.com/images/rss-to-jss-small.gif" alt='RSS to JavaScript' border="0">
</a>

</body>
</html> 
Creo que es un poco chapuza eso de meter un <script> dentro de un <div>, incluso creo que no se puede, pero bueno, funciona en IE6 y FF2 por lo menos...

Si quisieras hacerlo bien creo que habría que cargarlos en algún sitio oculto (iframe por ejemplo) y reescribirlos en el documento con su atributo target a nuestro gusto.


Un saludo.
__________________
- Haz preguntas inteligentes, y obtendrás más y mejores respuestas.
- Antes de postearlo Inténtalo y Búscalo.
- Escribe correctamente tus mensajes.