[英]Facebook like doesn't work in div
I'm using facebook like button on my blog I'm collect all social network like&share buttons in one div and I'm open that div with toggle link. 我在博客上使用了Facebook like按钮,我在一个div中收集了所有社交网络like&share按钮,然后使用切换链接打开了该div。 Twitter and google+ buttons work well but facebook like button doesn't work on firefox however it works on chrome.
Twitter和google +按钮可以正常工作,但是Facebook之类的按钮在Firefox上不起作用,但在chrome上可以工作。 By the way if I'm not use div its also works correctly on firefox.
顺便说一下,如果我不使用div,它也可以在Firefox上正常工作。 I don't know where is the problem.
我不知道问题出在哪里。
I think reason is javascript code execute on page load and div's property is display:none; 我认为原因是JavaScript代码在页面加载时执行,并且div的属性为display:none; maybe its effects the code.
也许影响代码。
<a href="#" onClick="$('.share').toggle();return false;"><b>Share</b></a>
<div class="share">
<div id="fb-root"></div>
<script>(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 = "http://connect.facebook.net/tr_TR/all.js#xfbml=1&appId=API_ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="url" data-send="false" data-layout="button_count" data-width="200" data-show-faces="false"></div>
</div>
Why don't you go through the documentation here and make sure you have done it properly. 您为什么不仔细阅读此处的文档,并确保已正确完成操作。
https://developers.facebook.com/docs/plugins/like-button/
. https://developers.facebook.com/docs/plugins/like-button/
。 Also, in your code. 另外,在您的代码中。 The problem is with how the fb-root is defined.
问题在于如何定义fb-root。 It is clearly mentioned in FB documentation that it should the first thing after body tag and for sure it is not inside any other div.
FB文档中明确提到,它应该放在body标记之后的第一位,并确保它不在任何其他div内。 Then you should define the JS needed to fetch FB library.
然后,您应该定义获取FB库所需的JS。
After that, put your button inside any div you like. 之后,将您的按钮放在您喜欢的任何div中。 There should not be any problem with that.
对此应该没有任何问题。
To be more clear: 更清楚地说:
<body>
<div id="fb-root"></div>
<script>(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 = "http://connect.facebook.net/tr_TR/all.js#xfbml=1&appId=API_ID";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<!-- Anything should be after this -->
<a href="#" onClick="$('.share').toggle();return false;"><b>Share</b></a>
<div class="share">
<div class="fb-like" data-href="url" data-send="false" data-layout="button_count" data- width="200" data-show-faces="false"></div>
</div>
I think you wanted the 'like' button to be inside the div, not the whole instantiation of FB JS SDK which was the mistake in your approach. 我认为您希望“喜欢”按钮位于div中,而不是FB JS SDK的整个实例化,这是您的方法中的错误。
Hope this helps! 希望这可以帮助!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.