How To Make The Facebook Like Button Display None When Logged In As Page

纵然是瞬间 提交于 2019-12-02 13:55:27

问题


I have the Facebook like button on my site http://theganjagirls.com ... everything looks and works fine when I'm logged into my Facebook account... But when I'm logged in as a page admin, the Facebook like button displays a "switch" link inside a big white box. Ive seen this happen on many big sites so I know its a problem with Facebook. I just went on to teespring.com/ganjagirls and they cleverly make the Facebook like button simply display:none when your logged in as a page admin.

So my question is: How do i make the Facebook like button display:none only if the viewing user is logged in to Facebook as a page admin?

I tried to do it my self by rapping the Facebook code in a container and using some JavaScript... but I'm amateur and I couldn't get it to work properly.

Here is what I got so far in CodePen: http://www.codepen.io/nouveau/pen/zfcLu.


回答1:


You could use a little script to set a timeout function and check the width of the widget

var timer;
$(window).load(function () {
    window.clearTimeout(timer);
    timer = window.setTimeout(function () {
        if ($('.fb-like').width() === 0) {
            $('.fb-like').hide();
            console.log('face');

        }
    }, 1000); // using 1000 milliseconds to work around load race
});

Working Example

Be aware you may run into a load-race. If the script runs before the widget loads this method may fail...




回答2:


I don't believe you can do that. Unless Facebook has made code for it, You can't just check for yourself.

Please remember that if you put in the default code for a Facebook like button, it will respond appropriately if the user is logged in.

Good luck!




回答3:


Wouldn't this: https://developers.facebook.com/docs/reference/javascript/FB.getLoginStatus/ (for getting the logged in status) combined with this: Facebook: get list of pages that a user is admin of (for getting the pages the user is admin of) be solution to your problem?




回答4:


put the icons in a container and apply the following css:

<style>.social-container{width:1px;height:1px;overflow:hidden}</style>


来源:https://stackoverflow.com/questions/16369247/how-to-make-the-facebook-like-button-display-none-when-logged-in-as-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!