引导弹出窗口中的Facebook分享按钮

时间:2019-01-17 12:05:32

标签: twitter-bootstrap facebook facebook-javascript-sdk bootstrap-popover

我试图让Facebook分享按钮在自举弹出窗口中正常工作。

但是它不起作用, 弹出窗口有效,但是在弹出窗口中共享按钮不可见

Instructions for the facebook share button

代码:

$('[data-toggle="popover"]').popover({
      trigger: 'click',
      html : true,
      content:  function() {
      	var content = '<div id="fb-root"></div><div class="fb-share-button" data-href="https://www.phoronix.com/scan.php?page=news_item&px=Ubuntu-Dock-CPU-Use-Third" data-layout="button_count"></div>'
        return $(content).html(); }
      
       }).on('shown.bs.popover',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 = "https://connect.facebook.net/en_US/sdk.js#xfbml=1&version=v3.0";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, 'script', 'facebook-jssdk'));
 
.row {
  background: #f8f9fa;
  margin-top: 20px;
}

.col {
  border: solid 1px #6c757d;
  padding: 10px;
}

.share {
  color: red !important;
}
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript" ></script>

<div class="container">
  <div class="row">
    <div class="col">
      <a tabindex="0" class="btn btn-default btn-lg share" role="button" data-toggle="popover" data-placement="right" title="Social media" data-content='<div id="foo">
       

        </div>'>test</a>
    </div>
  </div>
</div>

1 个答案:

答案 0 :(得分:0)

在动态创建的标签上,您必须使用此功能来重新解析社交插件:https://developers.facebook.com/docs/reference/javascript/FB.XFBML.parse/

在页面加载时(仅在页面加载时)加载JS SDK,并在回调中调用FB.XFBML.parse()