tsukimi
tsukimi

Reputation: 1645

twitter share button tweet intent retrieving the data-url

I have multiple twitter share buttons on a page, I want to identify which button was used to do a tweet by using the data-url property so i can record the tweet counts.I am using the twitter intents. How can i get the page url that the tweet refers to? This must be a common requirement.

<a href="https://twitter.com/share" class="twitter-share-button" data-url="http://www.example.com" data-lang="ja" data-counturl="http://www.example.com">ツイート</a>

twttr.ready(function (twttr) {
            twttr.events.bind('tweet', function (event) {
                alert(event.target);

            });
        });

Upvotes: 3

Views: 1529

Answers (1)

tsukimi
tsukimi

Reputation: 1645

I solved it doing this, the event.target is an iframe , so i parse the url from the src tag using a regular expression.

twttr.ready(function (twttr) {
    twttr.events.bind('tweet', function (event) {
        var url = unescape(event.target.src.match("url=(.*?)(&|$)")[1]);
        UpdateCounts("Tweet", url);

    });
});

Upvotes: 2

Related Questions