- Home
 - Categorie
 - Coding e Sistemistica
 - Coding
 - target _blank inserirlo per tutti i link esterni
 
- 
							
							
							
							
							
target _blank inserirlo per tutti i link esterni
Ciao a tutti, allora vorrei mettere nel mio sito il target="_blank" per i link esterni al sito. Però vorrei sapere se cè un modo per inserire questo attributo per tutti i link esterni senza dover inserirlo ad ognuno di essi ma con un qualche codice nella pagina.
GRazie
 - 
							
							
							
							
							
Ciao

Dovresti provare qualcosa del genere:
function externalLinks() { if (!document.getElementsByTagName) return; var anchors = document.getElementsByTagName("a"); for (var i=anchors.length-1; i>=0; i--) { var anchor = anchors*; if (anchor.href && anchor.href.substr(0,7) == "http://") anchor.target = "_blank"; } } window.onload = externalLinks;