Add MetaTags Using JavaScript

浪尽此生 提交于 2019-12-11 14:06:26

问题


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:


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", "");


来源:https://stackoverflow.com/questions/16895872/add-metatags-using-javascript

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