1

I have used jTwitter (jQuery plugin for Twitter) to retrieve and display tweets on my webpage. Everything is working except the links that are in tweets aren't clickable. I have tried different ways but I couldn't find a solution.

Here's the source

newstick.js

$(document).ready(

   function(){
        $.jTwitter('user', 10, function(data){
            $('#newsticker').empty();
            $.each(data, function(i, post){
                $('#newsticker').append(
                        ' <li>'
                        // See output-demo.js file for details
                        +    post.text
                        +' </li>'
                );
            });

        $("#newsticker").newsTicker();
            parseSamples();
        });

}   
);

I'm also using news ticker plugin so that I can display tweets as a ticker

<ul id="newsticker">

</ul>

Tweets are displaying somewhat like this but the links aren't clickable

jQuery Beginner: Checking how many elements were selected by $('.selector') http://t.co/berI7bu

jYouTube - jQuery YouTube plugin. Gets any video’s image http://t.co/vTxSmD5  
Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Switch
  • 14,783
  • 21
  • 69
  • 110
  • [jsfiddle](http://jsfiddle.com) please – genesis Sep 14 '11 at 19:01
  • In the example the links also aren't clickable so you would need to test post.text for http://... and then add an anchor tag around it, also are you using the newest version of jTwitter, since the link you posted goes to version 1.0 – jeffreydev Sep 14 '11 at 19:03
  • Yes I'm using the latest jTwitter version, and yes in the example also the links aren't clickable. I will try to go with that anchor adding method. – Switch Sep 14 '11 at 19:08

1 Answers1

0

I found a solution that uses regex

function replaceURLWithHTMLLinks(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>"); 
}

This simple funcion will turn non-clickable links to clickable. Found this in here

Community
  • 1
  • 1
Switch
  • 14,783
  • 21
  • 69
  • 110