/ Published in: JavaScript

Expand |
Embed | Plain Text
linkify_plain:function(text) { if( !text ) return text; text = text.replace(/((https?\:\/\/|ftp\:\/\/)|(www\.))(\S+)(\w{2,4})(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/gi,function(url){ nice = url; if( url.match('^https?:\/\/') ) { nice = nice.replace(/^https?:\/\//i,'') } else url = 'http://'+url; return '<a target="_blank" rel="nofollow" href="'+ url +'">'+ nice.replace(/^www./i,'') +'</a>'; }); return text; }
Comments

You need to login to post a comment.
You do know that that's not valid javascript and will cause an error? Don't just copy/paste some code from a script and expect it to work. Replace
linkify_plain:function(text)
withfunction linkify_plain(text)
Sorry I was using it in the context of...
object = { linkify_plain:function(text) { //code here } }
This function works OK, but actually it will replace all links including links in tags (IMG, existing A HREFs, STYLE etc.)