[英]How to reload/refresh a facebook like button when connecting to Facebook API via Javascript
I am using the JS API to connect to facebook within my website. 我正在使用JS API连接到我网站上的facebook。 This requires a click of a button and the users profile info etc.. is loaded in via javascript.
这需要单击按钮,并通过javascript加载用户个人资料信息等。
My problem is that I have a FB like button in my page: 我的问题是我的页面上有一个FB like按钮:
<div id="fb-like" style="position:absolute; left:340px; top:80px;">
<fb:like href="http://www.facebook.com/xxxxxx" send="true" width="450" show_faces="false" colorscheme="dark"></fb:like>
</div>
But when the users info is brought in, the like button doesnt show that im logged in. In order to see that im logged in, I need to refresh the page and then it says that ive liked it and which of my friends like it etc.. 但是,当引入用户信息时,“赞”按钮不会显示该即时消息已登录。为了查看该即时消息已登录,我需要刷新页面,然后说“我喜欢它,以及我的哪个朋友喜欢它,等等”。 ..
Is there a way to refresh the like button when the javascript login is complete? javascript登录完成后,有没有办法刷新点赞按钮?
Thanks :) 谢谢 :)
You can refresh the like button by editing DOM with javascript, reacting to the login event. 您可以通过使用javascript编辑DOM来刷新“赞”按钮,以响应登录事件。
Here is how i do it. 这是我的方法。
<div id="fblike" style="position:absolute; left:340px; top:80px;"></div>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId : '135669679827333',
status : true, // check login status
cookie : true, // enable cookies to allow the server to access the session
xfbml : true, // parse XFBML
//channelUrl : 'https://anotherfeed.com/emo/channel.html', // channel.html file
oauth : true // enable OAuth 2.0
});
function onlogin(){
var loginb=document.getElementById('fblike');
loginb.innerHTML='';
loginb.innerHTML='<div id="fb-like"><fb:like
href="http://www.facebook.com/xxxxxx" send="true" width="450"
show_faces="false" colorscheme="dark"></fb:like></div>';
FB.XFBML.parse(loginb);
};
FB.Event.subscribe('auth.login', function(response) {
onlogin();
});
FB.Event.subscribe('auth.logout', function(response) {
//window.location.reload();
});
}; // Load the SDK Asynchronously
(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/all.js#xfbml=1&appId=135669679827333";
fjs.parentNode.insertBefore(js, fjs); }(document, 'script',
'facebook-jssdk'));
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.