Advertisement
cdsatrian

like FB

Jun 22nd, 2012
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. yang jelas daftar dulu biar dapat facebook application ID; kalo udah tambahkan namespace facebook untuk halaman html aplikasi anda:
  2.  
  3. <html xmlns="http://www.w3.org/1999/xhtml" xmlns:fb="http://www.facebook.com/2008/fbml">
  4.  
  5. trus tambahin kode berikut untuk munculin tombol 'like' di tag <body> halaman aplikasi anda:
  6.  
  7. <div id="fb-root"></div>
  8. <script type="text/javascript">
  9. <!--
  10. window.fbAsyncInit = function() {
  11.  FB.init({appId: 'YOUR_FACEBOOK_APP_ID', status: true, cookie: true, xfbml: true});
  12.  FB.Event.subscribe('edge.create', function(href, widget) {
  13.         // tambahkan fungsi disini jika tombol 'like' ditekan
  14.                 // semisal munculkan link download, info tambahan atau apapun menurut kreasi anda
  15.      alert('kamu udah like '+href);
  16.  });
  17. };
  18. (function() {
  19.  var e = document.createElement('script');
  20.  e.type = 'text/javascript';
  21.  e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
  22.  e.async = true;
  23.  document.getElementById('fb-root').appendChild(e);
  24.  }());
  25. //-->
  26. </script>
  27.  
  28. nah kalo pake prototype.js bisa pake  kode ini:
  29. <script type="text/javascript" src="facebook.js"></script>
  30. <script type="text/javascript">
  31. <!--
  32. Event.observe(window, 'load', function() {
  33.         new facebookLikeButtonClass('YOUR_FACEBOOK_APP_ID', 'en_US', function(href, widgetObject) {
  34.                 // tambahkan fungsi disini jika tombol 'like' ditekan
  35.                 // semisal munculkan link download, info tambahan atau apapun menurut kreasi anda
  36.                alert('kamu udah like '+href);
  37.         });
  38. });
  39. //-->
  40. </script>
  41.  
  42. tentu mikir nih facebook.js itu isinya apa ya? ini isinya :
  43.  
  44. var facebookLikeButtonClass = Class.create({
  45.     initialize:function(appId, locale, callback)
  46.     {
  47.         window.fbAsyncInit = function() {
  48.             if (typeof FB == 'undefined') {
  49.                 return;
  50.             }
  51.             FB.init({appId: appId, status: true, cookie: true, xfbml: true});
  52.             FB.Event.subscribe('edge.create', function(href, widget) {
  53.                 if (callback != null) {
  54.                     callback(href, widget);
  55.                 }
  56.             });
  57.         };
  58.        
  59.         if ($('fb-root') == null) {
  60.             var fbEl = new Element('div', {id: 'fb-root'});
  61.             $(document.body).appendChild(fbEl);
  62.             var sc = new Element('script', { type:'text/javascript', src:document.location.protocol + '//connect.facebook.net/'+locale+'/all.js', async:true });
  63.             fbEl.appendChild(sc);
  64.             window.fbInitDone = true;
  65.         }
  66.     }
  67. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement