我发现这个对“login_event”的订阅只有在身份验证过程顺利进行后才会回来。因此,如果您尝试执行诸如显示带有“等待 Facebook”的加载模式以显示在慢速 2G 连接上的操作,那么这并不能真正帮助您。正如 Dave 所提到的,由于 Facebook 在 iframe 中显示它的按钮,因此您无法为其创建事件侦听器。
但是在文档之外,您会发现 Facebook 正在广泛使用窗口消息总线来与它的 iframe 对话。
window.addEventListener("message", receiveMessage, false);
function receiveMessage(event){
if(event.data.indexOf('_FB_') === 0){// these are facebook messages sent from it's iframes
if(event.data.indexOf('proxy_ready') > 0){
console.log('facebook ready');
}
}
}
在登录过程中通过控制台记录所有带有时间戳的消息并找出要关闭的消息会很有帮助。例子:
2016-12-14 15:13:38.024 app.js:162 FB.init
2016-12-14 15:13:39.257 app.js:1366 _FB_f120116a3bc6178data&logged_in=false&xd_action=proxy_ready
2016-12-14 15:13:43.473 app.js:1366 _FB_f120116a3bc6178type=resize&cb=f291741ffe877f&width=300&height=39
2016-12-14 15:13:47.933 app.js:1366 _FB_f120116a3bc6178xd_action=plugin_ready&name=f66bbdc3fb088&cb=f291741ffe877f&domain=xxx.xxx&origin=https%3A%2F%2Fxxx.xxx%2Ff120116a3bc6178&relation=parent.parent
2016-12-14 15:13:47.934 app.js:1366 _FB_f120116a3bc6178type=resize&width=164&height=39&reposition=false&cb=f291741ffe877f&domain=xxx.xxx&origin=https%3A%2F%2Fxxx.xxx%2Ff120116a3bc6178&relation=parent.parent
clicked button IN FB popup here:
2016-12-14 15:14:24.571 app.js:1366 _FB_f120116a3bc6178type=resize&cb=f291741ffe877f&width=300&height=39
2016-12-14 15:14:29.053 app.js:1366 _FB_f120116a3bc6178xd_action=plugin_ready&name=f66bbdc3fb088&cb=f291741ffe877f&domain=xxx.xxx&origin=https%3A%2F%2Fxxx.xxx%2Ff120116a3bc6178&relation=parent.parent
2016-12-14 15:14:29.055 app.js:1366 _FB_f120116a3bc6178type=refreshLoginStatus&cb=f291741ffe877f&domain=xxx.xxx&origin=https%3A%2F%2Fxxx.xxx%2Ff120116a3bc6178&relation=parent.parent
2016-12-14 15:14:29.071 app.js:1366 _FB_f120116a3bc6178type=resize&width=164&height=39&reposition=false&cb=f291741ffe877f&domain=xxx.xxx&origin=https%3A%2F%2Fxxx.xxx%2Ff120116a3bc6178&relation=parent.parent
2016-12-14 15:14:30.188 app.js:1366 _FB_f120116a3bc6178cb=fbcdc5c882b3bc&domain=xxx.xxx&origin=https%3A%2F%2Fxxx.xxx%2Ff120116a3bc6178&relation=parent&code=AQCl6y6TvwzareonnVCLEFWVglwDApABbs3ATKnbd6iLSZbKZ...mwZDZD&expires_in=6331&base_domain=xxx.xxx&https=1
2016-12-14 15:14:30.193 app.js:171 login_event
2016-12-14 15:14:30.193 app.js:172 connected
2016-12-14 15:14:30.193 app.js:173 Object {authResponse: Object, status: "connected"}
2016-12-14 15:14:30.199 app.js:246 FB.getLoginStatus
2016-12-14 15:14:30.201 app.js:229 connected to FB app
2016-12-14 15:14:30.202 app.js:253 FB.api