Facebook Developers
DocsToolsSupportNewsApps
Log In
  • Social Plugins
  • Facebook Login
  • Open Graph
  • Facebook APIs
  • Games
  • Media
  • Payments
  • App Center
  • Promote Your App
  • iOS
  • Android
  • Web
    • Getting Started
    • JavaScript SDK
    • PHP SDK
    • More SDKs
    • Facebook for WordPress
  • Technology Partners
  • Core Methods
    • FB.api
    • FB.init
    • FB.ui
  • Auth Methods
    • FB.getAuthResponse
    • FB.getLoginStatus
    • FB.login
    • FB.logout
  • Event Handling
    • FB.Event.subscribe
    • FB.Event.unsubscribe
  • XFBML
    • FB.XFBML.parse
  • Canvas Methods
    • FB.Canvas.Prefetcher.addStaticResource
    • FB.Canvas.Prefetcher.setCollectionMode
    • FB.Canvas.hideFlashElement
    • FB.Canvas.scrollTo
    • FB.Canvas.setAutoGrow
    • FB.Canvas.setDoneLoading
    • FB.Canvas.setSize
    • FB.Canvas.setUrlHandler
    • FB.Canvas.showFlashElement
    • FB.Canvas.startTimer
    • FB.Canvas.stopTimer

JavaScript SDK Reference

Web › JavaScript SDK Reference

The Facebook SDK for JavaScript provides a rich set of client-side functionality for adding Social Plugins, making API calls and implementing Facebook Login.

Take a look at the Getting Started guide for full information about features and usage.

The following code will load and initialize the JavaScript SDK with the most common options. Replace YOUR_APP_ID with your App ID from the App Dashboard, and WWW.YOUR_DOMAIN.COM with the path to your Channel File.

This code works best when placed directly after the opening <body> tag.

<div id="fb-root"></div>
<script>
  window.fbAsyncInit = function() {
    // init the FB JS SDK
    FB.init({
      appId      : 'YOUR_APP_ID',                        // App ID from the app dashboard
      channelUrl : '//WWW.YOUR_DOMAIN.COM/channel.html', // Channel file for x-domain comms
      status     : true,                                 // Check Facebook Login status
      xfbml      : true                                  // Look for social plugins on the page
    });

    // Additional initialization code such as adding Event Listeners goes here
  };

  // Load the SDK asynchronously
  (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/all.js";
     fjs.parentNode.insertBefore(js, fjs);
   }(document, 'script', 'facebook-jssdk'));
</script>

Full details on initializing the SDK can be found in the Getting Started section.

Methods

  • Core Methods
  • Auth Methods
  • Event Handling
  • XFBML
  • Canvas Methods

Core Methods

FB.api

Make an API call to the Graph API.

FB.init

Initialize the library.

FB.ui

Method for triggering Dialogs as popups, modal dialogs or as full pages. The dialogs are automatically formatted for mobile or desktop based on the client.


Auth Methods

FB.getAuthResponse

Synchronous accessor for the current authResponse.

FB.getLoginStatus

Find out the current status from the server, and get a session if the user is connected.

FB.login

Login/Authorize/Permissions.

FB.logout

Logout the user in the background.


Event Handling

FB.Event.subscribe

Subscribe to a given event name, invoking your callback function whenever the event is fired.

FB.Event.unsubscribe

Removes subscribers, inverse of FB.Event.subscribe.


XFBML

FB.XFBML.parse

Parse and render XFBML markup in the document.


Canvas Methods

FB.Canvas.Prefetcher.addStaticResource

Controls which static resources are flushed to the browser early.

FB.Canvas.Prefetcher.setCollectionMode

Controls how statistics are collected on resources used by your application, with the intent to influence whether those resources will be fetched to the browser early, or to turn off Prefetching completely.

FB.Canvas.hideFlashElement

Hides a Flash Element, used in conjunction with hideFlashCallback.

FB.Canvas.scrollTo

Tells Facebook to scroll to a specific location in the iframe of your canvas page.

FB.Canvas.setAutoGrow

Starts or stops a timer which resizes your iframe every few milliseconds.

FB.Canvas.setDoneLoading

Reports that the page is now usable by the user, for collecting performance metrics.

FB.Canvas.setSize

Tells Facebook to resize your iframe.

FB.Canvas.setUrlHandler

Registers the callback for inline processing (i.e. without page reload) of user actions, such as clicks on Live Ticker game stories.

FB.Canvas.showFlashElement

Display a Flash Element, used in conjunction with hideFlashCallback.

FB.Canvas.startTimer

When using setDoneLoading, controls the page load timer.

FB.Canvas.stopTimer

When using setDoneLoading, controls the page load timer.

Updated about a week ago
Facebook © 2013 · English (US)
AboutAdvertisingCareersPlatform PoliciesPrivacy Policy