我有以下haml
.share-fb-pop-up
.fb-contain
.fb-share-button{"data-href" => "https://fls.net/proficiency_test", "data-layout" => "button", "data-mobile-iframe" => "false", "data-size" => "small"}
%a.fb-xfbml-parse-ignore{:href => "https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Ffls.net%2Fproficiency_test&src=sdkpreparse", :target => "_blank"} Share
.pop-button-div
%button
Close
我加载了这样的javascript:
:javascript
window.fbAsyncInit = function() {
FB.init({
appId : '<my-app-id>',
xfbml : true,
version : 'v2.8'
});
};
(function(d, s, id){
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id)) {return;}
js = d.createElement(s); js.id = id;
js.src = "//connect.facebook.net/en_US/sdk.js";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
我知道它有效,因为我看到它生成文本“分享”,当我从.fb-xfbml-parse-ignore
标签中删除类a
时,它正确链接并通过脸书分享。是否与运行localhost或rails在页面中调用SDK有关?
谢谢!
答案 0 :(得分:1)
在加载共享按钮之前调用facebook-jssdk
初始化脚本。
id
FB.XFBML.parse(document.getElementById("<given-id>"))