autolink-js is a small (about half a kilobyte), simple, and tested JavaScript tool that takes a string of text, finds URLs within it, and hyperlinks them.

autolink-js adds an autoLink() method to JavaScript's String prototype, so you can use it on any JavaScript string. Take a look at the tests, but essentially, after including either autolink.js or autolink-min.js to your page, it works like this:

Input :

"This is a link to Google".autoLink()

Output :

"This is a link to Google <a href=''></a>"

Additional Options

You can pass any additional HTML attributes to the anchor tag with a JavaScript object, like this:

Input :

"This is a link to Google".autoLink({ target: "_blank", rel: "nofollow", id: "1" })

Output :

"This is a link to Google <a href='' target='_blank' rel='nofollow' id='1'></a>"

Example :

    <!-- Load jQuery and autolink-js -->
    <script src=''></script>
    <script src='../autolink.js'></script>
      <li>Our first item contains no links.</li>
      <li>Our second item contains a link to Google</li>
      <li class='new_window'>Our third item contains a link that opens in a new window</li>
      <li>Our fourth item contains a link to Google and a shortened bitly</li>
      <li class='callback'>Our fifth item contains a link to image</li>
    <script type='text/javascript'>
        $(document).ready(function() {
          $('li:not([class!=""])').each(function() {
            var that = $(this);
            var text = that.html();
          var callback = $('li.callback');
            callback.html().autoLink({ callback: function(url){
              return /\.(gif|png|jpe?g)$/i.test(url) ? '<img src="' + url + '">' : null;
          var new_window = $('li.new_window');
            new_window.html().autoLink({ target: "_blank" })