0

Im trying to check if my facebook page plugin has a certain class, but i cant get it to work.

The reason for this is that i whould like to show facebook page plugin only if you have not liked our company page before or if you a not logged in to facebook when you visit our website.

My code that dosent work

if($(".pluginConnectButtonDisconnected").hasClass("hidden_elem")){
         console.log('has hidden class');
} else {
         console.log('has no hidden class');
}

As you can see in below code the a element has class of hidden_elem but i cant get to return true allways false..? Please help :)

Below code is the page plugin code.

If check to see if the class of pluginConnectButtonDisconnected exsist it returs undefined even so i can see the plugin in front of med and i use the firebug console. Could it be that facebook dosent let you look into there code with jquery or something. Please help :)

Best regards.

user3502250
  • 343
  • 1
  • 5
  • 18
  • The code im trying to check against is this. – user3502250 Nov 06 '15 at 13:31
  • You have syntax errors in your code. Please use the dev tools in your browser of choice to help you fix them. – Brian Ray Nov 06 '15 at 13:48
  • Hi Brian. Thanks for info. If i use the console in firebug and write the following: console.log($( ".pluginConnectButtonDisconnected" ).hasClass("hidden_elem")) It stil returs false? where do u see a syntax error? – user3502250 Nov 06 '15 at 13:57
  • The syntax error I saw was that in your question, you have `.pluginConnectButtonDisconnected`, not `$('.pluginConnectButtonDisconnected')`. I just created a [fiddle](http://jsfiddle.net/hedo1c8u/) with the code you provided and it's returning true. The problem has to be somewhere else in your code. – Brian Ray Nov 06 '15 at 14:01
  • Thanks brian it dosent say tru in fiddle just shows "syntes godt om" if i remove that from the code i recive an empty result. So if i try to find the class in this code
    it dosent show anything but a blank response?
    – user3502250 Nov 06 '15 at 14:06
  • The javascript is printing out to the console. If you open the console tab of the dev tools in your browser, you will see it outputs `true`. – Brian Ray Nov 06 '15 at 14:08
  • Sorry your right, Do u think that facebook cut have done somthing to there facebook page plugin that does i cant check the code with jquery? I load the plugin before i run the script but it returns false. Its really strange, when i take a blank html file with the code and try it works fine but not on the website. ): could it be because of the iframe that the plugin usses? Thanks for your help. – user3502250 Nov 06 '15 at 14:17
  • The only thing I can think is that you're checking for `.pluginConnectButtonDisconnected` before it exists. Check [this](http://stackoverflow.com/questions/16149431/make-function-wait-until-element-exists) out on how to write a function that checks to see if it exists and repeats until it does. – Brian Ray Nov 06 '15 at 14:21
  • Your right it dosent exist if i try if ($('.pluginConnectButtonDisconnected').length) { console.log("Exists!"); } it says it's undefined. but its strange because when i try the code i have my firebug console open and the plugin is in front of me. and stille it says undefined. Do u know if there is any other way to not show the plugin if people has allready liked our company page. I tried the FB api but that only works if i have an app not a website. ): – user3502250 Nov 06 '15 at 14:26
  • I have no idea. I don't work on websites that utilize Facebook's API. – Brian Ray Nov 06 '15 at 14:27
  • 1
    Thanks for your help its much appreciated. – user3502250 Nov 06 '15 at 14:29
  • 1
    The plugin is rendered inside an iframe, and since the content of that iframe is from a different domain, you have no access to it via JavaScript. And besides, Facebook does not want you to treat users differently based on whether or not they liked your page – you should rather just show the same content to both groups. – CBroe Nov 06 '15 at 15:48
  • Thanks Cbro, I was thinking the same thing. The reason why i want to do this is because people that dont remember that they already have liked the page click on like ones again and that delete the like from the fb page, pretty stupid i think. – user3502250 Nov 06 '15 at 17:43

0 Answers0