Cross Domain Communication Channel

From Facebook Developers 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 establish a communication channel, create a channel file (usually xd_receiver.htm) with the following HTML:

<!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.debug.js" type="text/javascript"></script> </body> </html>


[edit] Usage

The Facebook JavaScript Library frequently requires the location of this file. It is always given relative to the root, taking the form "<relative path from root>/xd_receiver.htm".

For instance, if you store your application files in http://www.exampledomain.com/connect/, then the location would be "connect/xd_receiver.htm". Do not use a leading "/", ie. /connect/xd_receiver.htm!

An example of its use would be in the call to FB.Facebook.init, as the second parameter:


<script type="text/javascript"> FB_RequireFeatures(["XFBML"], function(){ FB.Facebook.init("YOUR_API_KEY_HERE", "<relative path from root>/xd_receiver.htm"); }); </script>


See XFBML#Initializing_Facebook_Connect for more details.

[edit] Notes

Note: 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.

See also: Cross Domain Communication