Why we need to add

前端 未结 3 1487
长情又很酷
长情又很酷 2021-02-04 23:11

Why we need to add these pair of tags within our facebook application. What\'s the use of this pairs of tags. I created an application which use an apprequest, and it works goo

相关标签:
3条回答
  • 2021-02-04 23:48

    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.

    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>
    
    0 讨论(0)
  • 2021-02-04 23:48

    UPDATE: Facebook no longer requires that you include <div id="fb-root"></div> in your HTML.

    You can now remove it. The Facebook Javascript SDK creates it on its own, appending it to the BODY tag. No warnings are shown in the console either, as it did before.

    The Facebook documentation has also been updated, no longer showing the <div id="fb-root"></div> requirement.

    Old documentation for version 1.0 (shows <div id="fb-root"></div>): https://developers.facebook.com/docs/javascript/quickstart/v1.0

    Current documentation for version 2.5 (no longer shows <div id="fb-root"></div>): https://developers.facebook.com/docs/javascript/quickstart/v2.5

    0 讨论(0)
  • 2021-02-04 23:50

    It gets even more simple with Turbolinks 5. You just need to add data-turbolinks-permanent=true to the fb-root div and it will be persisted between requests. No need to fiddle with the javascript.

    0 讨论(0)
提交回复
热议问题