Cross Domain Communication Channel

From Facebook Developer Wiki

Jump to: navigation, search

The Facebook JavaScript Client Library uses a cross-domain communications library to establish communication between third-party Web pages and Facebook pages and services inside a browser. To reference the library, you need to create a cross-domain communications channel file.

[edit] Creating the Channel File

  1. Create a file called xd_receiver.htm or download the file from http://www.somethingtoputhere.com/xd_receiver.htm.
  2. Add the following HTML code to the file:

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Cross-Domain Receiver Page</title> </head> <body> <script src="http://static.ak.facebook.com/js/api_lib/v0.4/XdCommReceiver.js?2" type="text/javascript"></script> </body> </html>
Note: The reference to ?2 is a temporary solution only for use in creating a Comments Box.
The channel file doesn't do much by itself; it's used as a parameter for various JavaScript Client Library methods, like FB.init:

<script type="text/javascript"> FB.init("YOUR_API_KEY_HERE", "<relative path from root>/xd_receiver.htm"); </script>


[edit] Location of Channel File

Only one channel file is required for each domain. Specify the channel file's location as a relative path that is either:

  • Relative to root, when prefixed with a forward slash ('/').
  • Relative to the file that's using it, when given in the form "<relative path from file>/xd_receiver.htm".

For instance, if you store your application files in http://www.exampledomain.com/connect/ and your channel file at http://exampledomain.com/connect/channel/xd_receiver.htm, then the location would be "channel/xd_receiver.htm". You don't need to have "connect" in there anywhere, we're specifying the link relative to the file not to the domain root.

When using a leading "/", as in: /channel/xd_receiver.htm, the receiver file must be placed relative to the root of your domain. This example would request the receiver file from http://www.exampledomain.com/channel/xd_receiver.htm.

[edit] Notes

  • Since the channel page is static and does not need to change, we recommend that you configure your Web server to allow browsers to cache the page. Typically, you can set the cache to expire internally after 30 days.
  • Question: Does this also work inside an fb:iFrame of an FBML page? I want to use Google Maps, but I need the iframe it's hosted in and the main page to talk to each other.
    • Answer: Yes it does.
  • Question: If you download the file (from step one) the parameter is ?v2 but if you cut and paste (from step two) the parameter is ?2 which one is correct?
  • Question: What should be the base of the url of the script? I have seen examples of both static.ak.facebook.com and static.ak.connect.facebook.com Thank you.
    • Answer: To reference it from within an iframe canvas page, use the following code:
      <script src="http://static.ak.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>

To reference it on a Facebook Connect site, use the following code:
<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>

Kunjungi web kami. http://www.bonuspulsa.com/?ref=324

reference