简体   繁体   English

试图在我的网站上添加像按钮一样的facebook

[英]trying to add facebook like button on my website

Below script will downlaod the facebook sdk to generate the code to create the like button 下面的脚本将下载facebook sdk以生成代码以创建like按钮

  (function() {
            var scrFaceBook = document.createElement('script');
            scrFaceBook.type = 'text/javascript';
            scrFaceBook.src = document.location.protocol +                            '//connect.facebook.net/en_US/all.js';
            scrFaceBook.async = true;
            document.getElementById('fb-root').appendChild(scrFaceBook);
        })();

<div class="fb-like" data-send="false" data-width="450" data-show-faces="true" data-font="arial"></div>

I am doing like this to add the FaceBook like button. 我这样做是为了添加FaceBook之类的按钮。 When I run my application and see I get "object does not support this property or method, all.js, uri: https://connect.facebook.net/en_US/all.js " 当我运行我的应用程序并看到我得到“对象不支持此属性或方法时,all.js,uri: https ://connect.facebook.net/en_US/all.js”

Can some one suggest me how do I fix this? 有人可以建议我如何解决这个问题? Thanks in advance. 提前致谢。

You forgot to add the <div id="fb-root"></div> to the body of the HTML. 您忘记将<div id="fb-root"></div>到HTML的正文中。

Also you seem to have forgotten the APP ID 你似乎忘记了APP ID

<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 = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=127211380649475";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

You need to make sure the dom element is declared above the script tag. 您需要确保在脚本标记上方声明了dom元素。 Otherwise it might not load: 否则可能无法加载:

<div class="fb-like" data-send="false" data-width="450" data-show-faces="true" data-font="arial"></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 = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=127211380649475";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

are your broswer support html5? 你的broswer支持html5? maybe the error is here "scrFaceBook.async = true;" 也许这里的错误是“scrFaceBook.async = true;”

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM