Javascript: Code from "twttr.events.bind('follow')" is executed on clicking Follow button, but user is not actually followed unless code contains an alert()


#1

I have a simple Javascript that should have the current window reload when the visitor Follows a user in Twitter. When I click the Follow button it greys out and reloads the page, however the user is not actually Followed on Twitter. However when I include an alert(); before location.reload(); it does work and the user is Followed on Twitter. How do I make this work properly without using alert();? This is my current code:

window.twttr = (function (d,s,id) { var t, js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js=d.createElement(s); js.id=id; js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs); return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } }); }(document, "script", "twitter-wjs"));
twttr.ready(function (twttr) {
  twttr.events.bind('follow',   function(e) {
    location.reload();
  });
});

</script>
    <a href="https://twitter.com/itsIniX" class="twitter-follow-button" data-show-count="false" data-size="large">Follow @itsIniX</a>

#2

The strange thing is when I try the following code (which includes ‘alert()’) from @chanian, it works like it’s supposed to. However when I replace the alert(); with location.reload(); or anything else it doesn’t work anymore:

<a href=http://twitter.com/directdialogs class="twitter-follow-button"

data-show-count="true">Follow@directdialogs</a>

<script type="text/javascript" charset="utf-8">

  window.twttr = (function (d,s,id) {

    var t, js, fjs = d.getElementsByTagName(s)[0];

    if (d.getElementById(id)) return; js=d.createElement(s); js.id=id;

    js.src="//platform.twitter.com/widgets.js"; fjs.parentNode.insertBefore(js, fjs);

    return window.twttr || (t = { _e: [], ready: function(f){ t._e.push(f) } });

  }(document, "script", "twitter-wjs"));

</script>

<script>

twttr.ready(function (twttr) {

  twttr.events.bind('follow',   function(e) {

     alert("FOLLOW!")

  });

});

</script>

#3