Jquery更改元标记 [英] Jquery to change meta tag

查看:84
本文介绍了Jquery更改元标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让这个元标记始终拥有它所在页面的当前网址。

I am trying to make this meta tag always have the current URL of the page it is on.

<meta property="og:url" content="http://shop.famsf.org/do/product/BK5160" />

我如何使用JS或JQ更改元标记?

How would I go about changing a meta tag with JS or JQ?

推荐答案

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

绝对可以使用jQuery更改元标记,但我不认为这会完成你想要什么,因为元标签是由FB刮刀拉动的。 FB刮刀熄灭并刮擦您的页面以读取元标记。

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

您可以通过更新网页的
代码来更新网页的属性。请注意,og:title和og:type最初只能编辑 -
在您的页面收到50个赞之后标题变得固定,而在
之后您的页面收到10,000个喜欢该类型变得固定。这些
属性是固定的,以避免令人惊讶的用户已经喜欢页面
。在达到
这些限制后更改标题或类型标签不起作用,您的页面保留原始标题和类型。

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.

要在Facebook上反映更改,你必须强制你的页面
被刮掉。当页面管理员点击
Like按钮或将URL输入Facebook URL
Linter时,该页面将被删除。您可以通过编程方式强制您的页面被
cURL'ing linter抓取。例如......

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/

但如果你想这样做:

$('meta[property=og\\:url]').attr('content', window.location.href);

这篇关于Jquery更改元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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