2013-03-20 51 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

相關問題