1

I've made this javascript code, to check if the user has liked my fb or not, what I want is to check from javascript that if the user, in this case, doesn't have the cookie show the div.

I've searched whatever I could find but couldn't actually figure it out.

 //fbb
  });
 //Additional


(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/en_US/sdk.js#xfbml=1&version=v2.4&appId";
  fjs.parentNode.insertBefore(js, fjs);
   FB.Event.subscribe('edge.create',
                        function (response) {
                            $(".fb-like").fadeOut();
                           setCookie("username", "user", "365");
                        }
                 );

}(document, 'script', 'facebook-jssdk'));




  function myFunction(){
    var dummytext=getCookie("username");
    console.log(dummytext);
    if (dummytext == "user") {
      $(".fb-like").fadeOut();
    } 
}
window.onload = myFunction;

So all I want to is that if dummytext != "user"/cookie doesn't exists, show this div:

<div class="name"><div class="fb-like" data-href="http://facebook.com/facebook/" data-layout="button" data-action="like" data-show-faces="false" data-share="false"></div></div>
IndigoMass
  • 27
  • 7
  • how about you call `myFunction()` inside the subscribe call back, with the parameters you need. – Ibu Jan 30 '17 at 23:48
  • Still it is a little bit annoying because the like div would still show up, and then disappear after the cookie checks out. – IndigoMass Jan 30 '17 at 23:53
  • You can reverse the condition then. Start with an invisible button, and only display it if the condition doesn't check out – Ibu Jan 30 '17 at 23:54
  • That is not allowed. Like gating is not allowed. – WizKid Jan 30 '17 at 23:57
  • Yup thanks, that can be done, making it show instead of hide. Sorry for being annoying but is it possible to insert a div like what I have from javascript or not. Everything I've tried so far failed so just curious. – IndigoMass Jan 30 '17 at 23:58
  • @WizKid I'm not like gating, this is kind of a popup for asking them to like, I'm not hiding content or forcing them to like. – IndigoMass Jan 30 '17 at 23:59
  • Gating means that you are showing them something different just because they liked your page. – WizKid Jan 31 '17 at 00:11
  • @WizKid As for my question, your comments are irrelevant again, since I'm not doing what you say. Anyway thanks. – IndigoMass Jan 31 '17 at 00:20
  • Yes you are. You say you want to show the popup depending if they have liked your page or not. – WizKid Jan 31 '17 at 00:52
  • this is pretty pointless anyway. if the user liked your page already and there is no cookie, he will still see the popup. – andyrandy Jan 31 '17 at 10:23

1 Answers1

0

Use JavaScript to check localstorage for the cookie. A simple if then should then suffice. I would use something like this for example. Or if you want an example in JQuery, go here.

Community
  • 1
  • 1
Colin
  • 865
  • 1
  • 6
  • 23