0

I been looking all over the internet for a code that does this, no luck so far... This is the code for my facebook like button:

<script type="text/javascript"> 

$(function(){
    $('<iframe scrolling="no" frameborder="0" style="width: 300px; height: 80px;'+
        '" src="http://www.facebook.com/widgets/like.php?href='+
            encodeURIComponent(location.href)+
        '"></iframe>').appendTo('#like-button')
})
</script>

I want this button to disappear after is clicked (Im thiyin to make some sort of like gate)

Cheers

Cœur
  • 37,241
  • 25
  • 195
  • 267
El Daniel
  • 1
  • 1
  • 1
    why would you want to do that? like gates are illegal and it is not cool for a user not to be able to unlike something. – andyrandy Nov 09 '14 at 00:32

2 Answers2

0

You can add this to your script:

$('#like-button').click(function(){
    $(this).hide();
});
Ax_6
  • 91
  • 9
  • sorry I've never used javascript before, where should i add this code? – El Daniel Nov 09 '14 at 03:04
  • you can put it at the beginning of the code right after the script tag – Ax_6 Nov 09 '14 at 09:34
  • did you test this? because it does not work at all. also, if you really want to use jquery for that simple code, at least use $(this).hide() instead. – andyrandy Nov 09 '14 at 09:50
  • No I didn't test it. I wrote it based on the question, so I'm not 100% if this is going to work – Ax_6 Nov 09 '14 at 09:56
  • when i tried the code it didn't worked, donno if I used it wrong or else, gotta try it latter, going to get some sleep now lol, maybe you can try implementing it yourself and see if it's working correctly – El Daniel Nov 09 '14 at 10:06
  • i tried it in jsfiddle because i was curious, it does not work. if you check out the link to another thread on stackoverflow in my answer > it´s about the exact same problem. – andyrandy Nov 09 '14 at 10:14
  • I'm not sure how did you test it, maybe I'm not understanding correctly, but this is my attempt and works: http://jsfiddle.net/x41qjz44/ – Ax_6 Nov 09 '14 at 10:22
  • Didnt work for me, I guess is related to the fact you are dealing with an Iframe... try using my code and see if it works: http://www.codeshare.io/UZVfH – El Daniel Nov 09 '14 at 19:20
0

First, why this is a bad idea:

  • Like Gates are no longer allowed, check out the changelog and the platform policy
  • It is annoying for the user if he can´t unlike something directly where he liked it.
  • Users can´t comment on the like button if you hide it right after clicking
  • Sometimes it needs confirmation to like something (for spam reasons, for example) - if you hide the button after clicking, the user can´t confirm and the like will not get through
  • It´s pointless anyway, because you will not be able to detect it for returning users so you would need to show the like button every time you refresh the page. You may use a cookie, but that´s not really a reliable solution.

...and please don´t try to solve the most simple things with jQuery. Instead of jQuery.appendTo, you can use appendChild, innerHTML, ... Learn JavaScript before using a library for it, or you will end up using it for everything - which is usually a lot slower than Vanilla JavaScript and not even less code in many cases.

That being said, it´s not that simple to hide it, you would need to use FB.Event.subscribe to subscribe to the like event: https://developers.facebook.com/docs/reference/javascript/FB.Event.subscribe/v2.2

See this thread, for example: Attach a click() event to the FaceBook 'Like' button?

And again, because it´s very important: Like Gates are not allowed!

Community
  • 1
  • 1
andyrandy
  • 72,880
  • 8
  • 113
  • 130
  • Like gates on FB pages are not allowed anymore, but FB cannot control what happens outside. thanks for the info tho, gootta check it later – El Daniel Nov 09 '14 at 10:04
  • they may not be able to control everything, but it´s still not allowed and you should not do it. and if someone reports your page...worst case is that your domain gets blocked on facebook. and then your like buttons will stop working at all. meaning: "they can´t control it" does not mean you should not care about rules. – andyrandy Nov 09 '14 at 10:11
  • that is really not a cool attitude. we are honest and serious developers here :/ – andyrandy Nov 09 '14 at 19:24