Twitter share button tweet intent retrieving the data-url


#1

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);

                });
            });

#2

That event.target object tells you the target DOM event that got interacted with. You can then leverage the DOM model to read attributes that you’ve applied to that original HREF, such as data-url or data-counturl or an arbitrary attribute you may have added yourself.


#3

The target is an iframe how would i get those properties, do you have an example? I can get the “src” tag and parse it but it would be better to take it directly.
This is how im doing it now , maybe a bit brittle.
event.target.src.match(“url=(.*?)&”)[1]


#4

Same here. the event object is empty, except for the “type” attribute which is set to “tweet”. This may be caused by the button being in an iframe.

Anyone knows a solution for this issue?


#5