开发者

jquery $('head').append and facebook share

i thought this was going to be simple but i don't know why is not working...

When you make facebook share button and you want some special image on the fb share, you put something like this in the <head> of the page:

<link rel="image_src" href="image.jpg" />

Facebook will then grab this image and put it in the post.

but i create this image after the page is loaded. so i wanted to put this piece of code into the after the page is loaded. I tried with this code:

$('head').append('<link rel="image_src" href="image.jpg" />');

but for some reason it doesnt work?

so how do i do that - append this piece of code into page after the page is loaded AND 开发者_开发技巧that facebook share button will grab this image?

thank you, Peter


you can check how facebook reads your site here: URL Linter

i think they only process html without executed javascript


The share-window loads the HTML of the site you want to share after you've clicked the share button. I personally don't think that it is able to execute JavaScript. Even if it could, it would have a different session and post-data. Also it get's cached.

In my experience it's just parsing the HTML without executing JavaScript.
If you use XFBML you could try calling FB.XFBML.parse(); after you appended the image, but I don't think this will work.


Maybe using the Open Graph tags instead could be a solution

https://developers.facebook.com/docs/reference/plugins/like/

Here's some more information, with examples:

https://developers.facebook.com/docs/opengraph/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜