Posted By

nikefido on 12/02/10


Tagged

twitterlinkhashtaguser


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

terrencewood


Linkify Twitter feed (Usernames, hashtags and links)


 / Published in: JavaScript
 

This will let you use the linkify_tweet() function on any string to make @username, #hashtags and http://any.links be clickable in your API-received twitter feeds.

  1. String.prototype.linkify_tweet = function() {
  2. var tweet = this.replace(/[A-Za-z]+:\/\/[A-Za-z0-9-_]+\.[A-Za-z0-9-_:%&\?\/.=]+/g, function(url) {
  3. var wrap = document.createElement('div');
  4. var anch = document.createElement('a');
  5. anch.href = url;
  6. anch.target = "_blank";
  7. anch.innerHTML = url;
  8. wrap.appendChild(anch);
  9. return wrap.innerHTML;
  10. });
  11. tweet = tweet.replace(/(^|\s)@(\w+)/g, '$1@<a href="http://www.twitter.com/$2" target="_blank">$2</a>');
  12. return tweet.replace(/(^|\s)#(\w+)/g, '$1#<a href="http://search.twitter.com/search?q=%23$2" target="_blank">$2</a>');
  13. };

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Swivel on January 3, 2012

I need what this code are used for, but in actionscript 3!!! thx

You need to login to post a comment.