简体   繁体   English

Facebook喜欢在div中不起作用

[英]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! 希望这可以帮助!

<a>在 a 内不起作用</a><div></div><div id="text_translate"><p>我有一个具有三种状态的按钮(三个不同的图像),除了按钮的主要 function 外,它可以工作并且看起来很棒 - 链接到其他文档:)</p><p> 当它被点击时,什么也没有发生。 我需要使用 javascript 或&lt;input&gt;或&lt;button&gt;吗?</p><p> 我已经用&lt;button&gt;标签试过了,但是这三种状态都不起作用。</p><p> 而且&lt;a id="backbutton"&gt; ... 也不起作用。</p><pre> #backbutton{ width: 100px; height:100px; background-image: url('../obrazky/fs/back_up100.png'); } #backbutton:hover{ background-image: url('../obrazky/fs/back_hover100.png'); } #backbutton:active{ background-image: url('../obrazky/fs/back_down100.png'); } &lt;div id="backbutton"&gt;&lt;a href="index.html"&gt;&lt;/a&gt;&lt;/div&gt;</pre></div> - <a> doesn't work within a <div>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Facebook Like Box不起作用 - Facebook Like Box doesn't work Facebook Like Button不起作用 - Facebook Like Button doesn't work 将facebook like按钮与查询字符串一起使用-like button不起作用 - Using the facebook like button with query strings - like button doesn't work Facebook缩略图无效 - Facebook thumbnail doesn't work 下拉 Div 不起作用 - Dropdown Div Doesn't Work Div重新加载无效 - Div reload doesn't work Javascript div 不起作用 - Javascript div doesn't work <a>在 a 内不起作用</a><div></div><div id="text_translate"><p>我有一个具有三种状态的按钮(三个不同的图像),除了按钮的主要 function 外,它可以工作并且看起来很棒 - 链接到其他文档:)</p><p> 当它被点击时,什么也没有发生。 我需要使用 javascript 或&lt;input&gt;或&lt;button&gt;吗?</p><p> 我已经用&lt;button&gt;标签试过了,但是这三种状态都不起作用。</p><p> 而且&lt;a id="backbutton"&gt; ... 也不起作用。</p><pre> #backbutton{ width: 100px; height:100px; background-image: url('../obrazky/fs/back_up100.png'); } #backbutton:hover{ background-image: url('../obrazky/fs/back_hover100.png'); } #backbutton:active{ background-image: url('../obrazky/fs/back_down100.png'); } &lt;div id="backbutton"&gt;&lt;a href="index.html"&gt;&lt;/a&gt;&lt;/div&gt;</pre></div> - <a> doesn't work within a <div> OnMouseDown不适用于Div - OnMouseDown Doesn't Work for Div Facebook“赞”按钮根本不显示 - The Facebook “Like” button doesn't show at all
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM