我尝试使用FB Javascript SDK进行Facebook登录。
登录后,仅在Opera浏览器中关闭登录窗口。 我该如何解决这个问题?
我尝试过以下源代码: (在this website - LINK)
中联机<html>
<head></head>
<body>
<div id="fb-root"></div>
<script>
window.fbAsyncInit = function() {
FB.init({
appId: '101103500012652', // App ID
channelUrl: '//www.milujse.cz/app/channel.html', // Channel File
status: true,
cookie: true,
xfbml: true
});
FB.Event.subscribe('auth.authResponseChange', function(response) {
if (response.status === 'connected') {
testAPI();
} else if (response.status === 'not_authorized') {
} else {
}
});
};
(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));
function testAPI() {
FB.api('/me', function(response) {
alert('Good to see you, ' + response.name + '.');
});
}
function loginFB()
{
FB.login(function(response) {
if (response.authResponse) {
testAPI();
} else {
}
});
}
function logoutFB()
{
FB.logout(function(response) {
});
}
</script>
<input type="button" value="Login" onclick="loginFB();
return false;" />
<input type="button" value="Logout" onclick="logoutFB();
return false;" />
</body>
</html>
答案 0 :(得分:2)
Opera中似乎存在一个错误,即Opera在某些情况下不支持windows上的window.close()函数。
这在javascript:window.close() and Opera以及https://bugzilla.mozilla.org/show_bug.cgi?id=190515处被引用,此处列为错误。
,似乎window.closed()事件在Opera中也是错误的答案 1 :(得分:2)
您是否考虑过检查浏览器以及是否使用其他方式连接Facebook的Opera,我的意思是使用oauth,您可以将整个页面重定向到Facebook登录页面而不是使用弹出窗口,因此您不会遇到问题无法关闭弹出窗口。 整个页面的链接就像 “https://graph.facebook.com/oauth/authorize?client_id=YOUR_CLIENT_ID&redirect_uri=http:YOUR_CALLBACK-URL&scope=WHAT_YOU_WANT”
答案 2 :(得分:1)
例如,关闭浏览器时编程浏览器独立的登录/注销逻辑很难实现。
使用以下代码检查并在setUser(null)
处设置断点package com.example.vaadintests;
import com.vaadin.Application; import com.vaadin.ui.Window; import com.vaadin.ui.Window.CloseEvent; import com.vaadin.ui.Window.CloseListener;
public class VaadintestsApplication extends Application
{
@Override
public void init()
{
final Window rootWindow = new Window();
setMainWindow(rootWindow);
rootWindow.addListener(new CloseListener()
{
@Override
public void windowClose(CloseEvent e)
{
setUser(null);
}
});
}
}