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

前端 未结 2 1240
时光取名叫无心
时光取名叫无心 2021-01-06 06:26

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

2条回答
  •  被撕碎了的回忆
    2021-01-06 07:16

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

提交回复
热议问题