Replace URL with HTML Link with Javascript and Jquery Plugins

This post contains useful jquery plugins and javascript tip how to replace text URL to HTML links. I hope it's very useful for your social media web projects. Thanks!

Javascript Text to Link
<script type="text/javascript">
function text_to_link(text) 
{
var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig;
return text.replace(exp,"<a href='$1' target='_blank'>$1</a>"); 
}
var linkdata=text_to_link("9lessons programming blog http://www.9lessons.info");
document.write(linkdata);
</script>

Labels:

Post a Comment

[facebook][blogger]

Author Name

Contact Form

Name

Email *

Message *

Powered by Blogger.