2012-10-19 16 views
1

所以我一直无法让我的Facebook像按钮一样工作。我试图将它们放在很多页面上,而无需每次都在代码段的'href'字段中输入url。我试过用js来动态改变href参数,但是当我点击'like'按钮时,它不会经过 - 又名不会发布到我的脸书。下面是代码:Facebook的问题,如按钮,XFBML,动态网址?

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

回答

2

只需删除href属性,SDK将自动使用当前页面的URL。