replace all linkable url in a string to real link  [ 710 views ]

As earlier to solve this is easy to extend the string object.

if(!String.linkify) {
  String.prototype.linkify = function() {
    // http://, https://, ftp://
    var urlPattern = /\b(?:https?|ftp):\/\/[a-z0-9-+&@#\/%?=~_|!:,.;]*[a-z0-9-+&@#\/%=~_|]/gim;
    // www. sans http:// or https://
    var pseudoUrlPattern = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
    // Email addresses
    var emailAddressPattern = /\w+@[a-zA-Z_]+?(?:\.[a-zA-Z]{2,6})+/gim;
    return this
      .replace(urlPattern, '<a href="$&" target="blank">$&</a>')
      .replace(pseudoUrlPattern, '$1<a href="http://$2" target="blank">$2</a>')
      .replace(emailAddressPattern, '<a href="mailto:$&" target="blank">$&</a>');
  };
}
#sidebar a { color:#fff; } #sidebar ul ul li { color: #DEF585; } #sidebar h2 { color: #fff; } #sidebar ul p, #sidebar ul select { color: #BEDDBE; } #backfly { background: url(images/golfBallWallPaper.jpg) left bottom fixed repeat-x #65a51d; }