且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么我们需要添加< div id ="fb-root"</div

更新时间:2021-06-30 22:50:27

它是Facebook javascript脚本的占位符,用于将元素附加到DOM.没有这个,在运行引用的Facebook脚本时,它就无处附加元素.

It's the place holder for the Facebook javascript script to attach elements to the DOM. Without this when the referenced Facebook script is ran it has nowhere to attach elements.

您可以看到fb-root作为初始化的一部分被附加了.

You can see fb-root gets appended to as part of the initialisation.

<script type="text/javascript">
      window.fbAsyncInit = function() {
        FB.init({appId: 'xxxxxx', status: true, cookie: true,
                 xfbml: true});
      };

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