Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 阻止Facebook js sharer中的某些图像_Html_Facebook_Facebook Sharer - Fatal编程技术网

Html 阻止Facebook js sharer中的某些图像

Html 阻止Facebook js sharer中的某些图像,html,facebook,facebook-sharer,Html,Facebook,Facebook Sharer,好吧,正如标题所述,有没有办法阻止Facebook js sharer的某些图片 FacebookJSSharer自动从页面获取图像,并允许用户选择在共享帖子中显示为缩略图的图像。目前,我们有一种情况,它获取页面上的广告图像,而不显示其他图像 我可以想象,横幅可以显示为div的背景图像,或者通过动态添加它们,但仍然可能有一个特殊的标记用于排除图像或共享init选项。。。在FB文档中找不到任何相关内容,但它们非常“具体” 要澄清上述内容,请查看标记: <!DOCTYPE html> &

好吧,正如标题所述,有没有办法阻止Facebook js sharer的某些图片

FacebookJSSharer自动从页面获取图像,并允许用户选择在共享帖子中显示为缩略图的图像。目前,我们有一种情况,它获取页面上的广告图像,而不显示其他图像

我可以想象,横幅可以显示为div的背景图像,或者通过动态添加它们,但仍然可能有一个特殊的标记用于排除图像或共享init选项。。。在FB文档中找不到任何相关内容,但它们非常“具体”

要澄清上述内容,请查看标记:

<!DOCTYPE html>
<html lang="en" 
      xmlns="http://www.w3.org/1999/xhtml" 
      xmlns:og="http://ogp.me/ns#"
      xmlns:fb="https://www.facebook.com/2008/fbml">
 <head>
  <meta property="og:image" content="/logo.jpg">
 </head>
 <body>
  <article>
   ..plain text content
  </article>
  <aside>
   <img src="/banner.jpg"> <!-- fetched image for share, wrong -->
  </aside>
 </body>
</html>

-但实际上,动态添加横幅(选择答案)并不是它的本意。

这是我给的一个C&p,尽管它也适用于这里:

解决您问题的一个方法可能是检查是否有真正的用户或Facebook机器人正在访问您的页面。如果是bot,则仅为其呈现必要的元数据。您可以通过其用户代理检测bot,该代理符合以下要求:
“facebookexternalhit/1.1(+http://www.facebook.com/externalhit_uatext.php)“

代码如下所示(在PHP中):


由于没有提供其他答案,因此标记为收藏夹。但实际上,我想得到更多的想法。。
function userAgentIsFacebookBot() {
    if ($_SERVER['HTTP_USER_AGENT'] == "facebookexternalhit/1.1 (+http://www.facebook.com/externalhit_uatext.php)") {
        return true;
    }
    return false;
}