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

拜拜、爱过 提交于 2019-12-30 10:28:08

问题


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.


回答1:


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

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.

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




回答2:


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. Twitterbot is in many ways really similar to Googlebot and similar indexers.

See https://dev.twitter.com/blog/twitter-cards-tips-tricks for a few examples of sites doing this.



来源:https://stackoverflow.com/questions/13467730/dynamically-adding-meta-tags-using-javascript-or-jquery-twitter-cards

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!