JavaScript Simplest Twitter Fan-gate / follower gate

Although this method allows you to asynchronously load the twitter library, but you need to make sure to setup the load before attempting to create the event handlers. Otherwise, you'll be greeted with a twttr undefined error.

Once loaded, the ready handler will fire which, in turn, allows us to setup the follow and unfollow handlers.

window.twttr = (function (d,s,id) { var t, js, fjs = d.getElementsByTagName(s)[0]; if (d.getElementById(id)) return; js=d.createElement(s);; js.src="//"; 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) {'follow', function(event) {
		// open up the gate!
		// reveal content, enable fields, etc., etc.
	});'unfollow', function(event) { 
		// close the gate!
Posted by
Snippet Viewed 1637 times.

Share your JavaScript code snippets:

  • Get some recognition & link back to your site.


Submit | Browse

Most Recent javascript snippets

Most Viewed