Add MetaTags Using JavaScript

2019-08-04 18:54发布

I have a website http://gornany.org/home/GammaGallery/1390?id=0

i want to show the image on Facebook profile which the user write a comment about, i want to change this code using JavaScript

<meta property="og:image" content="" />

i tried a lot of things like

$("meta[property='og\\\\\\\\:image']").attr("content","");
$('meta[property="og:image"]').attr('content',"" );

but nothing work Any help?

1条回答
孤傲高冷的网名
2楼-- · 2019-08-04 19:34

I dont think you can do that. Javascript is a client-side language so when Facebook reads the og:image meta tag the javascript code hasn't run yet. Hence, Facebook requests the page from the server and it will not be able to find the updated tags.

Check the debugger if you need to test this: http://developers.facebook.com/tools/debug

EDIT: But if in fact that was gonna work I think you need to escape your tag like:

$("meta[property='og\\:image']").attr("content", "");
查看更多
登录 后发表回答