2017-05-10 235 views
0

我裝兩個視頻靜態的FB-影片的內容和動態使用`FB.XFBML.parse重新加載,而不是重裝

FB.XFBML.parse(document.getElementById("container-id")); 

但不是重裝contaier重新加載整個第三個整個頁面頁。

<body> 
    <!-- Load Facebook SDK for JavaScript --> 
    <div id="fb-root"></div> 
    <script> 
    </script> 
    <!-- Your embedded video player code --> 
    <div id="video-basket"> 
     <div 
      class="fb-video" 
      data-href="https://www.facebook.com/facebook/videos/10153231379946729/" 
      data-width="500" 
      data-allowfullscreen="true"></div> 
     <div 
      class="fb-video" 
      data-href="https://www.facebook.com/MichaelMcIntyreFans/videos/1418120488209365/" 
      data-width="500" 
      data-allowfullscreen="true"></div> 
    </div> 

    <div id="cutty-video-basket"></div> 

    <script src="jquery.js"></script> 
    <script type="text/javascript"> 
     $(document).ready(function() { 
      facebook = ""; 
      /* Facebook videos initialization */ 
      window.fbAsyncInit = function() { 
       FB.init({ 
        appId: '{1367462833276100}', 
        xfbml: true, 
        version: 'v2.8' 
       }); 
       facebook = FB; 
      }; 
      (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/sdk.js"; 
       fjs.parentNode.insertBefore(js, fjs); 
      }(document, 'script', 'facebook-jssdk')); 
      /* Facebook videos initialization */ 

      /* Load the third video dynamically after five seconds */ 
      setTimeout(function() { 
       var str = '<div class="fb-video" data-href="https://www.facebook.com/thehumaneleague/videos/1740263742655957/" data-width="500" data-allowfullscreen="true"></div>'; 
       $("#cutty-video-basket").append(str); 
       facebook.XFBML.parse(document.getElementById("comment_basket")); 
      }, 5000); 
      /* Load the third video dynamically after five seconds */ 
     }); 
    </script> 
</body> 

但對於FB-意見相同的代碼工作正常,並沒有重新加載頁面只集裝箱。請注意,我已閱讀some questions but我需要的是動態加載fb-video 上一個新的div不是通過修改現有的數據href

回答

0

我不好,應該是

facebook.XFBML.parse(document.getElementById("cutty-video-basket")); 

facebook.XFBML.parse(document.getElementById("comment_basket")); 

值得注意的是按我的期望,它動態加載無需重新加載。

相關問題