最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Jquery to change meta tag - Stack Overflow

programmeradmin3浏览0评论

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

<meta property="og:url" content="" />

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

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/do/product/BK5160" />

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

Share Improve this question asked Sep 30, 2013 at 17:48 user2687646user2687646 2641 gold badge5 silver badges12 bronze badges 1
  • possible duplicate of Is it possible to use javascript to change the meta-tags of the page? – raina77ow Commented Sep 30, 2013 at 17:51
Add a ment  | 

4 Answers 4

Reset to default 2

Changing Facebook meta tag Content Attribute using JQuery

It is definitely possible to change meta tags using jQuery, but I don't think that's going to acplish 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 bees fixed, and after your page receives 10,000 likes the type bees 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./docs/opengraph/

BUT if you want to do this:

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

Select the element using tagname and attribute. Set the value using .attr():

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

You just grab a meta tags with the name 'og:url' and set its content attribute like this :

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

Property not working i used like that:

$("meta[name='og:url']").attr("content", location.href);
发布评论

评论列表(0)

  1. 暂无评论