2013-03-15 74 views
1

使用the example from the developer site:FB.ui返回錯誤:元素未指定

FB.ui(
    { 
    method: 'feed', 
    name: 'Facebook Dialogs', 
    link: 'https://developers.facebook.com/docs/reference/dialogs/', 
    picture: 'http://fbrell.com/f8.jpg', 
    caption: 'Reference Documentation', 
    description: 'Dialogs provide a simple, consistent interface for applications to interface with users.' 
    }, 
    function(response) { 
    if (response && response.post_id) { 
     alert('Post was published.'); 
    } else { 
     alert('Post was not published.'); 
    } 
    } 
); 

我得到以下回:

Error: element not specified 
innerError: undefined 
message: "element not specified" 

起初我還以爲我失蹤了 「FB-根」 元素,但我有它在我的身體:

<body onLoad="onLoad()"> 
    <div id="fb-root"></div> 
</body> 

現在我認爲它與我的Backbone/jQuery Mobile的用法有關,因爲正文第一頁加載後清除。然而,FB對象被加載,所以我真的不知道什麼是錯的。任何想法試圖解決這個問題?

謝謝。

+0

告訴我你不是用onLoad()函數做的嗎? – Gajotres 2013-03-15 17:57:41

+0

你實際上是否包含SDK? – Igy 2013-03-15 18:18:21

+0

不,這是在onLoad()之後。我在我的''中加載了一個js文件中的sdk,並設置了'window.fbAsyncInit'。 – Garrett 2013-03-15 22:19:08

回答

0

我遇到了同樣的問題,我發現這只是在Chrome上發生的。你正在使用哪種瀏覽器? 什麼工作對我來說是指定

display: 'popup' 

內FB.ui {}

此刻,我檢查瀏覽器和Chrome是否我用 '彈出',如果不是 'IFRAME'

var display = 'iframe'; 

    if (navigator.userAgent.toLowerCase().indexOf("chrome") != -1){ 
      display = "popup" 
    } 

    FB.ui({ 
     method: 'share', 
     display: display, 
     href: 'https://developers.facebook.com/docs/reference/dialogs/' 
     }, 
    function (response) {} 
); 

也應該與飼料,但我還沒有測試過。