简体   繁体   English

动态og:Facebook共享图片按钮

[英]Dynamic og:image for Facebook share button

Similar to this medium article where a custom og:image, og:title, and og:description are displayed for different articles, when the facebook share button is clicked a popup opens to let the user type a message and below is the image/title/description grabbed from meta tags (og:image, og:title, etc) 类似于这篇中篇文章 ,其中针对不同文章显示了自定义og:image,og:title和og:description,单击Facebook共享按钮时,会弹出一个弹出窗口,让用户键入消息,下面是图片/标题/描述从元标记(og:image,og:title等)中获取

When the user clicks on the facebook share button I then dynamically change the meta tags to customized images/descriptions using javascript like so 当用户单击“ facebook共享”按钮时,我便使用javascript这样将meta标签动态更改为自定义图像/描述

document.head.querySelector("[property='og:image']").setAttribute("content", image_url)

the problem is that the image isn't appearing at all when the fb share button is clicked - when I enter the url into Sharing debugger it works, but on the actual website it doesn't 问题是单击fb共享按钮时根本没有显示图像-当我在“共享调试器”中输入网址时,它可以工作,但是在实际网站上却没有

Not certain what your aim is but you won't be able to set the og:image using Javascript because facebook is getting the image url etc. from the HTML returned by the url when its own server requests that url. 不确定您的目标是什么,但是您将无法使用Javascript设置og:image,因为当其自己的服务器请求该URL时,facebook从该URL返回的HTML中获取图像url等。 It's not getting that data from the client. 它不是从客户端获取数据。

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

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