<html>
<head>
<title>Detectando automaticamente as URL contidas em um texto</title>
<script>
String.prototype.isUrl = function(targ){
this.ArrayTexto = this.split(" ");
this.tmpChar = "";
for (k=0; k<this.ArrayTexto.length; k++) {
this.idxUrl1 = this.ArrayTexto[k].slice(0,7);
this.idxUrl2 = this.ArrayTexto[k].slice(0,4);
if (this.idxUrl1 != "http://" && this.idxUrl2 != "www."){
this.tmpChar += this.ArrayTexto[k] + " ";
}
else{
this.Link = "";
if (this.idxUrl2 == "www.") this.Link = "http://";
this.Link += this.ArrayTexto[k];
if (this.Link.charAt(this.Link.length-1) == "."){
this.Link = this.Link.substring(0,this.Link.length-1);
}
this.tmpChar += "<a href=\"" + this.Link + "\" target=\"" + targ + "\">" + this.ArrayTexto[k] + "</a> ";
}
}
return this.tmpChar;
}
</script>
</head>
<body>
<script>
var texto = "Veja como é fácil gerar URLs automaticamente no site http://www.codigofonte.com.br/javascript. Entre também através do endereço www.codigofonte.com.br.";
document.write (texto.isUrl("_blank"));
</script>
</body>
</html>