2013-03-20 53 views
1

我使用下面的代码加载了Facebook的JavaScript SDK到我的网页: -如何解决我在加载Facebook javascript-sdk时遇到的错误?

  (function() { 
      console.log('Hello World! From self executing function.'); 
      var e = document.createElement('script'); 
      e.async = true; 
      e.type = 'text/javascript'; 
      e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js'; 
      document.getElementById('fb-root').appendChild(e); 
      console.log('javascript sdk is appended into the fb-root element of the page.'); 
     }()); 

是越来越正确加载,但我得到了下面的错误在我的控制台: -

Error: Permission denied to access property 'toString' 
    [Break On This Error]  

    ...5(i(ca.getElementsByTagName('*')),'forEach',true,function(ka){if(!ea&&ka.getAttr... 

如何解决这个问题?

任何帮助将感谢收到?

+1

您哪个浏览器出现此错误?在Chrome中添加此脚本时,似乎没有任何错误。 – Adidi 2013-03-20 08:35:55

+0

我现在正在使用FireFox。好的,我也会检查Chrome。 @Adidi我正在使用http://thinkdiff.net/facebook/new-javascript-sdk-oauth-2-0-based-fbconnect-tutorial/教程中的JavaScript代码。 – 2013-03-20 08:37:49

+0

@Adidi我也没有得到铬的任何错误。所以这只是一个浏览器特定的问题。 – 2013-03-20 08:48:08

回答

4

Facebook JavaScript SDK通常会导致跨浏览器问题。为了解决这个问题,Facebook本身已经集成了一个方法,即通过在FB.init()函数中添加一个频道url。

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 communication 
    status  : true, // check the login status upon init? 
    cookie  : true, // set sessions cookies to allow your server to access the session? 
    xfbml  : true // parse XFBML tags on this page? 
}); 

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

}; 

添加频道文件可解决跨浏览器问题。

的channel.html文件的内容应该只是一个单行:

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

内FB.init()的channelUrl参数是可选的,但强烈建议。提供频道文件可以帮助解决三个特定的已知问题。

  • 的页面包括码在帧之间进行通信可能导致社会 插件来显示为空白没有channelUrl。
  • 如果没有提供channelUrl且页面包括自动播放音频或视频,则用户可能会听到两个音频流,因为该页面已经在后台第二次加载了页面 以用于跨域 通信。
  • 通道文件将防止在您的 服务器端日志中包含额外命中。如果您未指定channelUrl,则应从日志中删除包含fb_xd_bust或fb_xd_fragment参数 的页面视图,以确保正确计数。

channelUrl必须是与您在其中包含SDK的页面匹配的完全限定的URL。换句话说,如果您的网站使用www服务,则频道文件域必须包含www,并且如果您在页面上修改document.domain,则必须在channel.html文件中进行同样的document.domain更改。

https://developers.facebook.com/docs/reference/javascript/

+0

哦,我傻了,我应该更仔细地阅读文件。 – 2013-03-20 11:53:22

相关问题