Poner target blank a enlaces externos

Si queremos que todos los enlaces externos de nuestra web se abran en una ventana nueva, podemos usar javascript a pelo sin necesidad de jquery

window.onload = function() {
   var links = document.getElementsByTagName('a');
   for (var i = links.length-1; i >= 0 ; i--) {
       if(links[i].host !== window.location.host) links[i].setAttribute('target', '_blank');
    }
}
Dejar un comentario?

0 Comentarios.

Deje un comentario


NOTA - Puede usar estosHTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Este sitio usa Akismet para reducir el spam. Aprende cómo se procesan los datos de tus comentarios.