开发者

Facebook Like Button on Google Chrome Extensions

开发者 https://www.devze.com 2023-04-05 23:00 出处:网络
I\'m trying to add a facebook like button to my extension. I\'ve already added a google +1 button but I seem to be having some trouble with the facebook button.

I'm trying to add a facebook like button to my extension. I've already added a google +1 button but I seem to be having some trouble with the facebook button.

This is the code generated by https://developers.facebook.com/docs/reference/plugins/like/ (Modified the source of the all.js file to be local instead)

<div id="fb-root"></div>
<script>(function(d, s, id) {
var js, fjs = d.getElementsBy开发者_运维问答TagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "all.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>
<div class="fb-like" data-href="https://chrome.google.com/webstore/detail/bkonffiagffjhnihbboojciggcplmobc" data-send="false" data-layout="button_count" data-width="450" data-show-faces="false"></div>

It doesn't show up at all on my extension, and I'm not exactly sure why.

Any tips would be great!

Thanks


The original src value for my like button was something like //connect.facebook.net/en_US/all.js#appId=<number>&xfbml=1. In a chrome extension, this url is extended to chrome-extension://connect.facebook.net/en_US/all.js#appId=<number>&xfbml=1, which will 404. The simple fix is to prepend the original src value with the http protocol, http://connect.facebook.net/en_US/all.js#appId=<number>xfbml=1.

I do not know the specifics of all.js, I can't say if embedding it in your extension will be useful.

(I ran into this same issue and thought I would leave my answer here for others.)

0

精彩评论

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