通过JavaScript更新Facebook Open Graph元标记 [英] Update Facebook Open Graph meta tag through JavaScript
问题描述
我正在尝试更新Facebook的Open Graph标题的元内容.我更新了内容,但是当它发布提要时,它仍然在提取旧信息.
I'm trying to update the meta content of the Facebook's Open Graph title. I updated the content, but when it published the feed, it's still pulling the old information.
示例:
<meta property="og:title" content="Title 1"/>
I managed to update to
<meta property="og:title" content="Title 2"/>
当我在Facebook Like上单击时,它仍将标题指向标题1".
When I click on the Facebook Like, it's still pointing the title to "title 1".
如何进行更新?
推荐答案
我想您已经知道了,但是其他人可能也有同样的问题.
I'm guessing you figured this out already, but others may have the same problem.
页面加载后,您无法使用JavaScript更改打开图"元标记,因为Facebook在查找元标记时再次从服务器请求页面,因此不会找到更新的标记.
You can't change the Open Graph meta tags with JavaScript after the pageload, as Facebook requests the page from the server again when looking for the meta tags, and so it will not find the updated tags.
此外,我发现Facebook只在标头中搜索Open Graph元标记,因此将它们添加到正文中也将不起作用.
Furthermore, I found that Facebook only searches the header for the Open Graph meta tags, so adding them in the body will not work either.
这篇关于通过JavaScript更新Facebook Open Graph元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!