Your Ad Here

Posted By

bitstream on 01/28/11


Tagged


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

alesma
maltem
withremote


autolink


 / Published in: jQuery
 

make websites and email address live (as links)

  1. jQuery.fn.autolink = function () {
  2. return this.each( function(){
  3. var re = /((http|https|ftp):\/\/[\w?=&.\/-;#~%-]+(?![\w\s?&.\/;#~%"=-]*>))/g;
  4. $(this).html( $(this).html().replace(re, '<a href="$1">$1</a> ') );
  5. });
  6. }
  7.  
  8. jQuery.fn.mailto = function () {
  9. return this.each( function() {
  10. var re = /(([a-z0-9*._+]){1,}\@(([a-z0-9]+[-]?){1,}[a-z0-9]+\.){1,}([a-z]{2,4}|museum)(?![\w\s?&.\/;#~%"=-]*>))/g
  11. $(this).html( $(this).html().replace( re, '<a href="mailto:$1">$1</a>' ) );
  12. });
  13.  
  14.  
  15. //Usage
  16. $(function(){
  17. $("#demo").autolink();
  18. $("#demo").mailto();
  19.  
  20. })

Report this snippet  

You need to login to post a comment.