仅Firefox:FB.init()之前调用FB.login() [英] Firefox Only: FB.login() called before FB.init()
本文介绍了仅Firefox:FB.init()之前调用FB.login()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用Facebook SDK,尝试将用户连接到我的网站时,会收到以下控制台错误。除了Firefox,连接Facebook按钮在所有其他浏览器中都可以正常工作。
Using the Facebook SDK, I get the following console error when trying to connect a user to my site. The "Connect with Facebook" button works fine in all other browsers, except Firefox.
我在innit配置中有一个频道URL,我已经确认了这个问题在Firefox中安装没有Firebug。以下是我的代码:
I have a Channel URL in the innit config, and I've confirmed this issue happens in Firefox installs without Firebug. The following is my code:
<script type="text/javascript">
window.fbAsyncInit = function() {
FB.init({
appId : 'my_real_app_id',
channelUrl : 'MYURL.com/channel.php',
status: true,
cookie: true,
xfbml : false
});
};
(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));
$(document).ready(function() {
$('a#login-fb').click(function(event) {
event.preventDefault();
FB.login(function(response) {
if (response.authResponse) {
console.log('Welcome! Fetching your information...');
FB.api('/me', function(response) {
handleFacebookLogin(response);
});
} else {
console.log('User cancelled login or did not fully authorize');
}
}, {scope: 'email, offline_access, user_birthday, publish_stream, publish_actions' });
});
</script>
推荐答案
我通过更改我上面的javascript来修正这个问题以下#fb-root到以下内容:
I fixed this issue by changing my above javascript, right below #fb-root to the following:
<div id="fb-root"></div>
<script type="text/javascript">
$(document).ready(function() {
window.fbAsyncInit = function() {
FB.init({
appId : 'my_id',
status: true,
cookie: true,
xfbml : false
});
};
(function() {
var e = document.createElement('script');
e.async = true;
e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
document.getElementById('fb-root').appendChild(e);
}());
//rest of code here
这篇关于仅Firefox:FB.init()之前调用FB.login()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文