Facebook 身份验证页面不会关闭或刷新父级
Facebook 身份验证效果很好。我可以提取用户的个人资料图片和姓名。但是,当您单击“登录”并且出现 facebook 提示时,我遇到了两个问题(在 IE 和 Chrome 中)。
首先,窗户永远不会关闭。它只是转到一个空白的白页。这实际上是通过网络发生在我身上的。 Turntable.fm 登录以及我能想到的任何 Facebook 连接网站都可以这样做。我在工作时、家里的多台不同电脑上都会遇到这种情况。 FB坏了吗?我忍不住认为这与其他问题有关...
关闭(空白)登录弹出窗口后,我的页面不会刷新。
这些就是问题所在。我尝试订阅 auth.login 事件并在那里调用 reload() ,这是文档建议的,但这在您登录时不会刷新。这还导致了一个问题,如果您注销,它只会自动登录这就是为什么我添加了下面的代码来检测注销并重新加载。这确实有效。那么我怎样才能让它在弹出窗口关闭时重新加载,或者更好的是,让弹出窗口自行关闭并重新加载我的页面?!
下面所有相关的FB代码(我认为):
window.fbAsyncInit = function () {
FB.init({
appId: '123456', // App ID
channelURL: 'http://www.mydomain.net/channel.html', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
oauth: true, // enable OAuth 2.0
xfbml: true // parse XFBML
});
//update guest/username if logged in or not
FB.getLoginStatus(function (response) {
if (response.authResponse) {
FB.api('/me', function (response) {
$('#UserMenu').show();
$('#Login').hide();
$('#fbpic').html('<img alt="Account Picture" src="https://graph.facebook.com/' + response.username + '/picture" />');
$('#AccountName').html(response.name);
getVentID(response.id, response.name);
$('#Logout').show();
});
} else {
//not logged in to facebook
}
});
$('#Logout').live('click', function () {
FB.logout(function (response) {
// user is now logged out
window.location.reload();
});
});
//subscribe to login changes
FB.Event.subscribe('auth.login', function (response) {
});
};
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
} (document));
Facebook authentication is working great. I can pull the profile pic and name of the user. However, when you click login and the facebook prompt comes up I have two problems (in both IE and Chrome).
First off, the window never closes. It just goes to a blank white page. This is actually happening to me across the web. turntable.fm logins do this as well as any fb connected sites I can think of. it happens to me at work, at home on multiple different PCs. Is fb broken? I can't help but think this is related to the other issue...
My page doesn't refresh after I close the (blank) login popup.
So those are the issues. I tried subscribing to the auth.login event and calling a reload() there, which is what the documentation recommends, but this didn't refresh when you logged in. It also caused a problem where if you logged out it would just automatically log you back in. That's why I added the code below to detect a logout and reload. That actually works. So how can I make it reload when the popup window is closed, or even better, make the popup window close itself and reload my page?!
all relevant fb code below (I think):
window.fbAsyncInit = function () {
FB.init({
appId: '123456', // App ID
channelURL: 'http://www.mydomain.net/channel.html', // Channel File
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
oauth: true, // enable OAuth 2.0
xfbml: true // parse XFBML
});
//update guest/username if logged in or not
FB.getLoginStatus(function (response) {
if (response.authResponse) {
FB.api('/me', function (response) {
$('#UserMenu').show();
$('#Login').hide();
$('#fbpic').html('<img alt="Account Picture" src="https://graph.facebook.com/' + response.username + '/picture" />');
$('#AccountName').html(response.name);
getVentID(response.id, response.name);
$('#Logout').show();
});
} else {
//not logged in to facebook
}
});
$('#Logout').live('click', function () {
FB.logout(function (response) {
// user is now logged out
window.location.reload();
});
});
//subscribe to login changes
FB.Event.subscribe('auth.login', function (response) {
});
};
// Load the SDK Asynchronously
(function (d) {
var js, id = 'facebook-jssdk'; if (d.getElementById(id)) { return; }
js = d.createElement('script'); js.id = id; js.async = true;
js.src = "//connect.facebook.net/en_US/all.js";
d.getElementsByTagName('head')[0].appendChild(js);
} (document));
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是因为我在 Chrome 中“安装”了 Facebook!卸载后现在到处都可以使用。太高兴了!
This was because I had Facebook "installed" in Chrome! Uninstall and now it works everywhere. SOOO happy!