新的 Facebook 点赞按钮 HTML 验证 [英] New Facebook like button HTML validation

查看:36
本文介绍了新的 Facebook 点赞按钮 HTML 验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的页面上添加新的 facebook like 按钮后,它不再使用 XHTML 严格标准进行验证.我遇到的两个错误是:

After adding the new facebook like button on my page, it's no longer validates using XHTML strict standard. The two errors I come across are:

  1. 所有的meta property标签都表示没有属性property;
  2. 在like按钮行中使用的所有变量都列出来了,没有它的属性.线路如下:

  1. All of the meta property tags say that there is no attribute property;
  2. All of the variables used in the like button line are listed that there are no attributes for it. The line is as follows:

<fb:like href="http://www.pampamanta.org" layout="button_count" show_faces="false" width="120" action="like" font="arial" 配色方案="光"></fb:like>

推荐答案

这里有一个不交换文档类型的解决方案:

正如 zerkms 所建议的,添加fb"命名空间仅适用于fb:"属性.元标记的属性"属性仍然是无效的 XHTML.

As zerkms suggested, adding the "fb" namespace only applies for the "fb:" attributes. The "property" attribute of the meta tag remains invalid XHTML.

如您所知,Facebook 建立在 RDFa 合规性之上,因此您可以使用以下文档类型:

As you know, Facebook builds upon the RDFa compliance, so you could use the following doctype:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd"> 

尽管在大多数情况下,使用 RDFa 会带来比简单的 FB 问题修复更多的问题.

Using RDFa brings more problems than the simple FB issue fix in most cases though.

正如 _timm 所建议的,将元标记动态写入 dom 没有任何意义.这些 fb 元标记的主要用途之一是 FB-bot 对分享"或我喜欢"目标页面(操作页面)的解析,以为 Facebook 墙贴自动填充提供自定义标题、图像和锚标签.鉴于这一事实,并且鉴于 facebook 肯定会使用简单的页面获取来读取传递的 html 响应,而没有任何解析由 javascript 注入的相关元标记的能力,预期的功能将简单地失败.

as _timm suggested, dynamically writing the meta tags to the dom doesn't make any sense. One of the major uses of these fb meta tags is the FB-bot parsing of a "share" or "i like" target page (action page) to provide custom titles, images and anchor label for the facebok wall post auto population. Given that fact and given the fact that facebook most certainly uses a simple page fetch to read in the delivered html response without any capability of parsing a related meta tag inject by javascript, the intended functionality will simply fail.

现在,有一个非常简单的修复方法可以在 XHTML 验证和 facebook 成功解析之间提供折衷:将 facebook 元数据包装在 html 注释中.这绕过了 w3c 解析器,而 facebook 仍然可以识别元标记,因为它忽略了评论.

Now, there is a pretty simple fix to provide a compromise between a XHTML validation and successful parsing by facebook : wrap the facebook meta in html comments. That bypasses the w3c parser and facebook still recognizes the meta tags, cause it ignores the comment.

<!--
<meta property="og:image" content="myimage.jpg" />
<meta property="og:title" content="my custom title for facebook" />
-->

这篇关于新的 Facebook 点赞按钮 HTML 验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆