Kaah
Kaah

Reputation: 1211

Add target=“_blank” to link with JavaScript

Simple question: How do you add target=“_blank” to the returned link in the following function?

   String.prototype.parseHashtag = function() {
    return this.replace(/[#]+[A-Za-z0-9-_]+/g, function(t) {
        var tag = t.replace("#","%23")
        return t.link("http://search.twitter.com/search?q="+tag);
    });

It is printed like this:

$("#twitterFeed span").html(data[twitterNumber].text.replace(urlRegexp, "<a target=_blank href='$1'>$1</a>").parseHashtag().parseUsername());

Upvotes: 1

Views: 1126

Answers (1)

Ja͢ck
Ja͢ck

Reputation: 173662

You probably have to do it yourself:

return t.link("http://search.twitter.com/search?q="+tag)
    .replace(/^<a/, '$& target="_blank"');

Upvotes: 2

Related Questions