Facebook Recommend Ignoring og:title Until Page Refreshed

旧巷老猫 提交于 2019-12-23 19:26:29

问题


I have the typical HTML5 implementation of the Facebook recommend button:

<div id="fb-root"></div>
<script type="javascript">
(function(d, s, id) {
    var js, fjs = d.getElementsByTagName(s)[0];
    if (d.getElementById(id)) return;
    js = d.createElement(s); js.id = id;
    <? if ( $current_language == 'en' ): ?>
        js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
    <? else: ?>
        js.src = "//connect.facebook.net/fr_CA/all.js#xfbml=1";
    <? endif; ?>
    fjs.parentNode.insertBefore(js, fjs);
} (document, 'script', 'facebook-jssdk'));
</script>

<div class="share_button facebook" id="facebook">
    <div class="fb-like" data-send="false" data-layout="button_count" data-width="80" data-show-faces="false" data-action="recommend"></div>
</div>

The first time I click it, the popup preview box does not display the Title or Description. I have the following info at the top of the page: Test

<meta http-equiv="Content-Script-Type" content="text/javascript" />
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1" />
<meta name="description" content="Test website." />
<meta name="keywords" content="test whatever" />
<meta property="og:title" name="Show this!" content="Show this!" />

If I leave the page, unrecommend the page from Facebook and return to the same page and press Recommend again, the title and description then appear. The page shows one of thousands of db entries so the problem needs to be fixed. I have tried putting the js function in jQuery(document).ready(function() - no luck. I tried moving it to the bottom of the page - no luck. Can someone help me?


回答1:


From the example you gave, you are missing some required OG tags such as URL and image. Also, do you have the prefix info on your head tag?

<head prefix="og: http://ogp.me/ns# fb: http://ogp.me/ns/fb# myspecialapp: http://ogp.me/ns/fb/myspecialapp#">


来源:https://stackoverflow.com/questions/12501196/facebook-recommend-ignoring-ogtitle-until-page-refreshed

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!