LINKIFY Example - Basic Roll Your Own Function/Plugin
HTML
<div id="example">Hier stehen ein paar Links: www.facebook.com (http://www.google.de(google)) oder http://www.amazon.de oder auch www.adac.de <br/><br/>Und Emailadressen gehen auch: [email protected]</div>
JavaScript
(function($) {
$.linkify = function(el) {
var inputText = el.html();
//URLs starting with http://, https://, or ftp://
var replacePattern1 = /(\b(https?|ftp):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim;
var replacedText = inputText.replace(replacePattern1, '<a href="$1" target="_blank">$1</a>');
//URLs starting with www. (without // before it, or it'd re-link the ones done above)
var replacePattern2 = /(^|[^\/])(www\.[\S]+(\b|$))/gim;
replacedText = replacedText.replace(replacePattern2, '$1<a href="http://$2" target="_blank">$2</a>');
//Change email addresses to mailto:: links
var replacePattern3 = /(\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,6})/gim;
replacedText = replacedText.replace(replacePattern3, '<a href="mailto:$1">$1</a>');
el.html(replacedText);
}
})(jQuery);
$(function() {
$.linkify($('#example'));
});