1

I'm trying to call a function after a user follows me, and this seems to work just fine on desktop. However on mobile since the popup opens up a new tab rather than a popup window as it does on desktop, its not capturing the callback. Any ideas?

<script>
    window.twttr = (function(d, s, id) {
        var js, fjs = d.getElementsByTagName(s)[0],
            t = window.twttr || {};
        if (d.getElementById(id)) return t;
        js = d.createElement(s);
        js.id = id;
        js.src = "https://platform.twitter.com/widgets.js";
        fjs.parentNode.insertBefore(js, fjs);

        t._e = [];
        t.ready = function(f) {
            t._e.push(f);
        };
        return t;
    }(document, "script", "twitter-wjs"));

    twttr.ready(
        function(twttr) {
            twttr.events.bind(
                'follow',
                function(event) {
                    var followedUserId = event.data.user_id;
                    if (followedUserId == "1234567890") {
                        console.log("Following Twitter account.");
                    }
                }
            );
            twttr.events.bind(
                'unfollow',
                function(event) {
                    var followedUserId = event.data.user_id;
                    if (followedUserId == "1234567890") {
                        console.log("Unfollowing Twitter account.");
                    }
                }
            );
        }
    );
</script>

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Browse other questions tagged or ask your own question.