简体   繁体   English

使用javascript或jquery [推特卡]动态添加元标记

[英]Dynamically adding meta tags using javascript or jquery [twitter cards]

I want to add twitter card meta tags to my website. 我想将twitter card meta标签添加到我的网站。 i cannot add static tags since the content attribute in the meta tag has to change dynamically. 我无法添加静态标签,因为meta标签中的content属性必须动态更改。 Plz help if someone has a solution. 如果有人有解决方案,请帮助。

You can't, at least not in any way that Twitter is going to recognise. 您至少不能以任何方式无法识别Twitter。

When Twitter fetches the page, it is always going to get the meta elements that are in the HTML, never ones added with client side JavaScript. 当Twitter获取页面时,它将始终获取HTML中的meta元素,而不是与客户端JavaScript一起添加的meta元素。

If you are changing content dynamically then make use of the history API to update the URI, and make sure that the server will generate all the content for each URI when the URI is used as an entry point (you can still use JavaScript to generate the content when moving from another page on the site). 如果您要动态更改内容,则可以使用历史记录API更新URI,并确保当URI用作入口点时,服务器将为每个URI生成所有内容(您仍然可以使用JavaScript来生成URI内容从网站上的另一个页面移出时)。

You can generate pages dynamically (server side) as long as you don't intend to change them after. 您可以动态地生成页面(服务器端),只要您不打算以后进行更改即可。 Think about the process in the same way you would build landing pages for SEO purposes. 以与您出于SEO目的构建登录页面相同的方式来考虑该过程。 Twitterbot is in many ways really similar to Googlebot and similar indexers. Twitterbot在许多方面与Googlebot和类似的索引器确实非常相似。

See https://dev.twitter.com/blog/twitter-cards-tips-tricks for a few examples of sites doing this. 请参阅https://dev.twitter.com/blog/twitter-cards-tips-tricks,以获得一些执行此操作的站点示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM