开发者

Anyway to append this script to the body after setTimeout

开发者 https://www.devze.com 2023-03-04 17:33 出处:网络
I am trying to append this script below to the end of the body after setTimeout of 3 seconds. The issue i am having is that, I am loading the facebook javascript all.js 3 seconds after the page has lo

I am trying to append this script below to the end of the body after setTimeout of 3 seconds. The issue i am having is that, I am loading the facebook javascript all.js 3 seconds after the page has loaded for performance reasons, but it does not rec开发者_运维知识库ognize the settings, so i want to append this script to the body when i load the facebook javascript. How can i do this?

<script>
  FB.init({
    appId  : 'myappid',
    status : true,
    cookie : true,
    xfbml  : true 
  });
</script>


Why would you append the script? Simply invoke this method in your callback for the setTimeout:

function initializeFacebookThing()
{
    setTimeout(function()
    {
       if(someComponentIsLoaded)
       {
           FB.init({
              appId: 'myappid',
              status: true,
              cookie: true,
              xfbml: true
           });
       }
       else
       {
            initializeFacebookThing();
       }
    }, 3000);
}

This way, you even get loading wait time tolerance.

0

精彩评论

暂无评论...
验证码 换一张
取 消