简体   繁体   English

如何通过 url 参数更改开放图形元标记内容

[英]How to change open graph meta tag content via url params

I am trying to make a custom embed generator using url parameters and open graph meta tags, but whenever I post the link to sites such as Discord, it uses the default tags I've set for it rather than the url parameter ones.我正在尝试使用 url 参数和打开图形元标记来制作自定义嵌入生成器,但是每当我将链接发布到 Discord 等网站时,它都会使用我为它设置的默认标签,而不是 Z572D4E4E4E42D81E5A8B711 参数。 Does anyone know how to fix this?有谁知道如何解决这一问题? I've posted the code and an example image of what happens below.我已经发布了代码和下面发生的示例图像。

 <html prefix="og: https://ogp.me/ns#"> <head> <meta property="og:title" content="Title"> <meta property="og:description" content="Description"> <script> const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); if (urlParams.has("title")) { const title = urlParams.get("title"); document.querySelector('meta[property="og:title"]').setAttribute("content", title); }; if (urlParams.has("desc")) { const desc = urlParams.get("desc"); document.querySelector('meta[property="og:description"]').setAttribute("content", desc); }; </script> </head> </html>

You can't expect from crawlers that fetch open graph data to execute JS on your page.您不能指望抓取打开的图形数据在您的页面上执行 JS 的爬虫。 Only valid solution would be to render this HTML on server.唯一有效的解决方案是在服务器上呈现此 HTML。

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

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