2012-08-07 27 views
0

我們有一個奇怪的問題,我們的網站與Facebook評論。它看起來像Facebook的刮板不正確地解析(至少有一個)我們的網頁,以便它不會採取管理員來緩和評論。無法設置管理員的Facebook評論

如果你去這個鏈接:

http://www.beliefnet.com/Espanol/10-Atletas-olimpicos-mas-inspiradores.aspx

和查看源代碼,你會看到我們在頭適當的標籤,其中包括一個FB:管理員。如果我登錄到該帳戶的臉書,我沒有任何版主選項。

通過Facebook對象調試器運行頁面,我得到一個錯誤,我們有正文中的元標記。具體而言,這樣的錯誤:

Meta Tags In Body: You have tags ouside of your . This is either because 
your was malformed and they fell lower in the parse tree, or you accidentally 
put your Open Graph tags in the wrong place. Either way you need to fix it 
before the tags are usable. 

看着那個頁面底部的刮網址,我看看有什麼看起來是Facebook的「重組」我們的HTML,並放置在meta標籤從頭部到身體。

有沒有人有任何想法是什麼造成這種情況?我認爲也許我們在頁面的某處放置了一些格式不正確的html,但是我瀏覽了該頁面的html,看起來不錯。還有什麼我在這裏失蹤?

回答

1

所以問題最終是在頭部嵌套了一個<noscript>...</noscript>,這是爲了在未啓用javascript的情況下爲瀏覽器添加跟蹤像素,這是我們使用的廣告服務的一部分。

問題應該已經很明顯看輸出的Facebook給了我們「他們看到的頁面」。身體在腳本之後立即開始,但緊接在標籤開始之前。顯然,當facebook解析器看到一個頭部中的元素應該在身體中時,它會嚇壞了,所以它立即在那裏啓動身體。

... Facebook的輸出...

 console.log(OAS); 
    })(); 
</script><!-- End OAS Setup --><!-- Begin comScore Tag --><script> 
     var _comscore = _comscore || []; 
     _comscore.push({ c1: "2", c2: "8428430" }); 
     (function() { 
     var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true; 
     s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js"; 
     el.parentNode.insertBefore(s, el); 
     })(); 
    </script> 
</head> 
<body> 
<noscript> 

    </noscript> 
    <!-- End comScore Tag --> 

...我們的HTML ...

<head> 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 

    <asp:PlaceHolder id="OASHeader" runat="server" /> 

    <!-- Begin comScore Tag --> 
    <script type="text/javascript"> 
     var _comscore = _comscore || []; 
     _comscore.push({ c1: "2", c2: "8428430" }); 
     (function() { 
     var s = document.createElement("script"), el = document.getElementsByTagName("script")[0]; s.async = true; 
     s.src = (document.location.protocol == "https:" ? "https://sb" : "http://b") + ".scorecardresearch.com/beacon.js"; 
     el.parentNode.insertBefore(s, el); 
     })(); 
    </script>  
    <!-- End comScore Tag --> 
    <noscript> 
     <img src="http://b.scorecardresearch.com/p?c1=2&c2=8428430&cv=2.0&cj=1" alt="" /> 
    </noscript> 

    <script type="text/javascript"> 
    .... 
    <body> 
    .... 

所以在未來,無效的頭元素絕對可以導致此問題。

+0

不錯的發現和後續帖子! – 2012-08-09 05:24:24

1

奔跑穿過validator.w3.org您的網址顯示了一些警告標誌:

Line 77, Column 14: document type does not allow element "noscript" here; assuming missing "object" start-tag 
Line 154, Column 699: document type does not allow element "meta" here 

我能夠(潛在)問題縮小到這些線在你的頁面:

document.write('<a href="' + OAS.config.url + 'click_nx.ads/' + OAS.config.sitepage + '/1' + OAS.config.rns + '@' + OAS.config.listpos + '!' + pos + '?' + OAS.config.query + '" target=' + OAS.config.target + '>'); 
document.write('<img src="' + OAS.config.url + 'adstream_nx.ads/' + OAS.config.sitepage + '/1' + OAS.config.rns + '@' + OAS.config.listpos + '!' + pos + '?' + OAS.config.query + '" border=\"0\" /></a>'); 

這些document.write()的線路也未能在w3.org驗證:

Line 53, Column 197: character "+" is not allowed in the value of attribute "target" 

此外,我認爲這'S b ad使用document.write()進行DOM插入(並且因爲它可能導致阻止頁面呈現)。 你可以改變使用js對象和DOM操作嗎?

FB獲取您的URL後,它通過DOM解析器運行它,當它遇到那些document.write()行時可能會窒息。這些行橫跨兩個document.writes()有一個<a>元素的事實可能會令分析器感到困惑。解析器可能認爲它已經到達頁面的<正文>,因此「正文中的元標籤」錯誤。

作爲一個快速測試,請嘗試將fb:admins元標記放在這些document.write()行的上方。不過,如果解析器仍然ch咽,我不會感到驚訝,但它值得一試。

要測試你的網頁的HTML源,我用這個php.net頁月底在評論中提供的簡單腳本: http://www.php.net/manual/en/class.domxpath.php

它產生的錯誤:

Unexpected end tag : a in /home/dlee/tmp/tmp.html, line: 54 
Unexpected end tag : head in /home/dlee/tmp/tmp.html, line: 183 
htmlParseStartTag: misplaced <body> tag in /home/dlee/tmp/tmp.html, line: 184 

哪裏TMP。 html是保存到文件中的頁面的html。 第54行是前面提到的document.write()行。

讓我知道如果任何進行中的上述結果,我會相應地編輯此答案。

+0

THX的意見,它實際上把我在正確的軌道上。看到我的帖子的答案。 – 2012-08-08 20:35:06