所以我一直无法让我的 facebook like 按钮正常工作。我试图将它们放在许多页面上,而不必每次都在片段的“href”字段中输入网址。我尝试使用 js 动态更改 href 参数,但是当我单击“喜欢”按钮时,它不会通过 - 也就是不会发布到我的 Facebook。这是代码:
<script>
window.fbAsyncInit = function() {
// init the FB JS SDK
FB.init({
appId : '456678891040542', // App ID from the App Dashboard
channelUrl : '//WWW.UNICONUTRITION.COM/channel.html', // Channel File for x-domain communication
status : true, // check the login status upon init?
cookie : true, // set sessions cookies to allow your server to access the session?
xfbml : true // parse XFBML tags on this page?
});
// Additional initialization code such as adding Event Listeners goes here
};
// Load the SDK's source Asynchronously
(function(d){
var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
if (d.getElementById(id)) {return;}
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
ref.parentNode.insertBefore(js, ref);
}(document));
</script>
<li class="sloo"><fb:like id="fb" href="www.asdf.com" layout="box_count"></fb:like>
</li>
<script type="text/javascript">
var sUrl = window.location;
document.getElementById('fb').setAttribute('href', sUrl);
</script>