检查用户机是否可以访问Facebook [英] Check if user machine can access Facebook
问题描述
有谁知道如何解决这个问题?我的意思是如何检查用户机器是否可以访问Facebook?
我通过使用Facebook API设法实现了这一点。只需启动一个查询,并调用FB.XFBML.parse();当查询完成时。
< script type =text / javascript>
window.fbAsyncInit = function(){
FB.init({
appId:'app id',
status:false,
cookie:true,
xfbml:false,
oauth:false
});
FB.api({
method:'fql.query',
query:'SELECT uid,name FROM user WHERE uid = 1234'
},
function (response){
if(response [0] .uid =='1234'){//现在用户可以连接到Facebook
FB.XFBML.parse();
}
});
};
(function(){
var e = document.createElement('script');
e.src = document.location.protocol +'//connect.facebook.net/en_US/ all.js';
e.async = true;
document.getElementById('fb-root')。appendChild(e);
}());
< / script>
Facebook is banned in our country. However there are still a considerable amount of users who can work around to use Facebook. Of course, many others can't. My site uses Facebook like button and like box. If the user machine cannot access Facebook, there will be some "ugly" parts on the page, where there should be Facebook plugin.
Does anyone know how to resolve this issue? I mean how to check if the user machine can access Facebook? Any trick is appreciated.
I managed to achieve this by using Facebook API. Just initiate a query, and call FB.XFBML.parse(); when the query completes.
<script type="text/javascript">
window.fbAsyncInit = function () {
FB.init({
appId: 'app id',
status: false,
cookie: true,
xfbml: false,
oauth: false
});
FB.api({
method: 'fql.query',
query: 'SELECT uid,name FROM user WHERE uid=1234'
},
function (response) {
if (response[0].uid == '1234') { // Now that the user can connect to facebook
FB.XFBML.parse();
}
});
};
(function() {
var e = document.createElement('script');
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
e.async = true;
document.getElementById('fb-root').appendChild(e);
}());
</script>
这篇关于检查用户机是否可以访问Facebook的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!