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

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

问题描述

我想将 Twitter 卡片元标记添加到我的网站.我无法添加静态标签,因为元标签中的内容属性必须动态更改.如果有人有解决方案,请帮忙.

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 中的元元素,而不是使用客户端 JavaScript 添加的元元素.

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 卡] 动态添加元标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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