使用 JQuery 更改 Facebook 元标记内容属性

发布于 2024-11-29 14:19:15 字数 546 浏览 3 评论 0原文

我想知道如何使用 JQuery 来替换 Facebook 元标记的内容属性。

我搜索了 StackOverflow,发现了这个例子:

$("meta[property=og:title]").attr("content", title);
$("meta[property=og:url]").attr("content", url);

在我的代码中,我有以下元标记:

<meta property="og:title" content="some content"/>
<meta property="og:url" content="some content"/>
<meta property="og:site_name" content="some content"/>

当我运行应该更改“title”和“url”变量内容的函数时,更改不会发生地方。 “内容”的相同值仍然保持不变。

我想知道如果可能的话,如何使用 JQuery 更改 Facebook 元标记的值。

I want to know how can I use JQuery in order to replace the content attribute of my Facebook meta tags.

I searched StackOverflow and what I've found was this example:

$("meta[property=og:title]").attr("content", title);
$("meta[property=og:url]").attr("content", url);

In my code I have the following meta tags:

<meta property="og:title" content="some content"/>
<meta property="og:url" content="some content"/>
<meta property="og:site_name" content="some content"/>

When I run the function that should change the content for the 'title' and 'url' variables, the change doesn't take place. The same values for the 'content' still remains the same.

I want to know how, if it's possible, to use JQuery to change the value of Facebook's meta tags.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

萌能量女王 2024-12-06 14:19:15

这就是它对我的作用:

$('meta[name=og\\:url]').attr('content', newVideoUrl);

注意双反斜杠,没有它 Jquery 将失败并出现错误。

This is how it worked for me:

$('meta[name=og\\:url]').attr('content', newVideoUrl);

note the double backslash, without it Jquery will fail with an error.

难得心□动 2024-12-06 14:19:15

使用 jQuery 更改元标记绝对是可能的,但我认为这不会实现您想要的效果,因为元标记是由 FB 抓取工具拉取的。 FB 抓取工具会抓取您的页面以读取元标记。

编辑元标签

您可以通过更新页面的属性来更新页面的属性
标签。请注意,og:title 和 og:type 只能编辑
最初 - 当您的页面收到 50 个赞后,标题就会固定,
当你的页面收到 10,000 个赞后,类型就固定了。
这些属性是固定的,以避免让喜欢的用户感到惊讶
页面已经。在这些限制之后更改标题或类型标签
已到达 不执行任何操作,您的页面保留原始标题并且
类型。

为了使更改反映在 Facebook 上,您必须强制您的页面
被刮掉。当页面管理员点击时,页面会被抓取
点赞按钮或在 Facebook URL 中输入 URL 时
短绒。您可以通过编程强制您的页面被抓取
卷曲短绒。例如...

https://developers.facebook.com/docs/opengraph/

It is definitely possible to change meta tags using jQuery, but I don't think that's going to accomplish what you want since the meta tags are pulled by the FB scraper. The FB scraper goes out and scrapes your page to read the meta tags.

Editing Meta Tags

You can update the attributes of your page by updating your page's
tags. Note that og:title and og:type are only editable
initially - after your page receives 50 likes the title becomes fixed,
and after your page receives 10,000 likes the type becomes fixed.
These properties are fixed to avoid surprising users who have liked
the page already. Changing the title or type tags after these limits
are reached does nothing, your page retains the original title and
type.

For the changes to be reflected on Facebook, you must force your page
to be scraped. The page is scraped when an admin for the page clicks
the Like button or when the URL is entered into the Facebook URL
Linter. You can programmatically force your page to be scraped by
cURL'ing the linter. For example ...

https://developers.facebook.com/docs/opengraph/

微暖i 2024-12-06 14:19:15

Facebook 抓取工具执行 JavaScript。

因此,使用 Javascript 修改元标签以显示不同的共享内容是行不通的。

您需要使用服务器端代码根据需要将它们写在 HTML 源代码中。

The Facebook scraper doesn't execute JavaScript.

So using Javascript to modify the metatags in order to show different share content won't work.

You'd need to use serverside code to write them out as needed in the HTML source.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文