New Facebook like button HTML validation

前端 未结 15 1951
抹茶落季
抹茶落季 2020-12-02 11:34

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. All of the
15条回答
  •  暖寄归人
    2020-12-02 12:01

    Here is a solution for not swapping doctype:

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

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

     
    

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

    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.

    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.

    
    

提交回复
热议问题