使用javascript或jquery [twitter card]动态添加元标记 [英] Dynamically adding meta tags using javascript or jquery [twitter cards]

查看:101
本文介绍了使用javascript或jquery [twitter card]动态添加元标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将twitter card meta标签添加到我的网站.由于meta标签中的content属性必须动态更改,因此我无法添加静态标签. 如果有人有解决方案,请帮助.

I want to add twitter card meta tags to my website. i cannot add static tags since the content attribute in the meta tag has to change dynamically. Plz help if someone has a solution.

推荐答案

您至少不能以Twitter能够识别的任何方式.

You can't, at least not in any way that Twitter is going to recognise.

Twitter提取页面时,总是会获取HTML中的meta元素,而不是客户端JavaScript中添加的meta元素.

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.

如果您要动态更改内容,请使用历史记录API 更新URI,并确保当URI用作入口点时,服务器将为每个URI生成所有内容(当您从网站上的另一个页面移动时,仍可以使用JavaScript来生成内容)

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).

这篇关于使用javascript或jquery [twitter card]动态添加元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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