Facebook JavaScript SDK [英] Facebook JavaScript SDK

查看:101
本文介绍了Facebook JavaScript SDK的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有一个简单的问题,似乎我缺少明显的东西.在实际使用其中的方法之前,Facebook Javascript SDK需要进行初始加载.建议异步加载:

Hi all,
I have a simple question as it seems that I''m missing something obvious. Facebook Javascript SDK requires an initial load, before you can actually use the methods within it. It is recommended to load it asynchronously:

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    FB.init({
      appId      : 'YOUR_APP_ID', // App ID
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      oauth      : true, // enable OAuth 2.0
      xfbml      : true  // parse XFBML
    });

    // Additional initialization code here
  };

  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     d.getElementsByTagName('head')[0].appendChild(js);
   }(document));
</script>



问题是,我是否需要在使用SDK的每个页面上调用



The question is, do I need to call

FB.init()

,还是只需调用一次"init"并包含

on each page that uses the SDK, or it is enough to call ''init'' once and include

<script src="//connect.facebook.net/en_US/all.js"></script>

脚本标记在其他网页上.在此先感谢.

script tag on other web pages. Thanks in advance.

推荐答案

提供的浏览器会话未关闭,那么您只需要在开始时调用一次FB.init(),其余的只需调用一次即可.应该保留在内存中.


如有疑问,请尝试一下!


(毕竟,您不能造成任何伤害:))
Providing the browser session isn''t closed, then you should only have to call FB.init() once at the start, the rest should remain resident in memory.


If in doubt, just try it out!


(You can''t do any harm after all :) )


这篇关于Facebook JavaScript SDK的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆