新的Facebook喜欢按钮HTML验证 [英] New Facebook like button HTML validation

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

问题描述

在我的页面上添加新的Facebook的按钮之后,它不再使用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. 所有的元属性标签表示没有属性属性;

  2. 列出了类似按钮行中使用的所有变量,它们没有属性。行如下:

  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.orglayout =button_count show_faces =falsewidth =120action =likefont =arialcolorscheme =light>< / fb:like>


推荐答案

以下是不交换doctype的解决方案:

如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的基础上,因此您可以使用以下doctype:

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.

as _timm建议,将元标记动态写入dom并没有任何意义。这些fb元标签的主要用途之一是FB-bot解析共享或我喜欢的目标页面(动作页面),为自动人脸贴图提供自定义标题,图像和锚标签。鉴于这一事实,并且鉴于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成功解析之间的妥协:在html评论中包装Facebook meta。绕过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天全站免登陆