问题
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