Facebook OAuth登录成功,无法返回初始窗口,仅适用于IE
Facebook OAuth Login Success not returning to originating window for IE only
我正在使用新的Facebook登录:
window.fbAsyncInit = function () {
FB.init({
appId: '@facebookAppId', // App ID
status: true, // check login status
cookie: true, // enable cookies to allow the server to access the session
xfbml: true, // parse XFBML
oauth: true
});
runFbInitCriticalCode();
};
function runFbInitCriticalCode() {
// Additional initialization code here
FB.Event.subscribe('auth.login', function () {
window.location = "/facebookPostAuth.aspx";
});
FB.Event.subscribe('auth.logout', function (response) {
});
// Hack to fix http://bugs.developers.facebook.net/show_bug.cgi?id=20168 for IE7/8/9
FB.UIServer.setLoadedNode = function (a, b) { FB.UIServer._loadedNodes[a.id] = b; };
};
// 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));
有谁知道为什么在弹出login SUCCESS和登录弹出窗口关闭后,成功结果没有返回到登录页面或发起人页面?
问题与IE所需的P3P标头有关。
我们总是通过这样做在我们的项目(MVC3 ASP.NET)中添加这个头:
protected override void OnResultExecuting(ResultExecutingContext filterContext)
{
base.OnResultExecuting(filterContext);
// You need this to allow IE to have cross domain cookies and sessions
filterContext.HttpContext.Response.AddHeader("P3P:CP", "IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT");
filterContext.HttpContext.Response.AddHeader("Access-Control-Allow-Origin", FacebookSettings.CurrentConfig().CanvasUrl);
}
你可以在这里找到更多信息:
Iframe Facebook应用程序和cookie [Internet Explorer]
发现FB.Event.subscribe('auth.login')不是100%可靠的,因为它有时不命中。
当我在IE中调试JavaScript时,它可以工作。当我不调试与IE开发工具,它通常无法击中。
我设置了一个JavaScript时间间隔作为IE检查收到的FB令牌的保险(这非常有效,因为我总是在登录成功后获得accesstoken,即使登录事件订阅在不调试时在IE中不起作用)。
仍然……如果有人知道这个问题的原因,请随时发布。
没有使用需要初始化的Facebook按钮,我设置了自定义锚/按钮,它使用JavaScript单击事件处理程序显式调用登录函数。这解决了IE的特殊性,我不再需要一个时间间隔来检查何时收到令牌。此外,我可以从一开始就对它进行样式化,而不是在原来的FB初始化登录按钮上进行样式化。
http://developers.facebook.com/docs/reference/javascript/FB.login/对于click事件,我调用:
FB.login(function(response) {
if (response.authResponse) {
//Token, Login Status can be grabbed from response.authResponse
} else {
console.log('User cancelled login or did not fully authorize.');
}
}, {scope: 'email'});
相关文章:
- IE窗口失去了对任何XMLHttpRequest启动Angular应用程序的关注
- 新的弹出窗口比IE中预期的要小
- window.打开IE 11中的新选项卡而不是新窗口
- Page.ClientScript.RegisterClientScriptBlock窗口.打印无法在IE中工作
- 显示模态对话;在 IE 中打开一个新窗口
- 如何在IE中检测弹出窗口阻止程序
- IE 错误窗口.onload 不会始终如一地触发
- Selenium IE Driver 打开新窗口,而不是 window.open() 上的新选项卡
- 如何让 VB Web 浏览器控件单击无法在控件中手动单击但可以在实际 IE 窗口中单击的按钮
- 如何通过单击按钮自动打开子窗口作为焦点窗口(IE)
- IE 窗口.在第二个会话时打开 打开一个具有第一个会话 ID 的窗口
- 弹出窗口重定向在IE中不起作用,但在其他浏览器中可以
- VBS - IE - 脚本在javascript弹出窗口中单击“确定”
- 窗口.打开为什么某些用户的IE每次都会打开新窗口
- 如何从IE和Chrome浏览器中的显示模式对话框窗口返回数组对象
- Extjs 窗口在 IE 中不能很好地显示元素
- 检测 Firefox、IE 和 Chrome 中的窗口 onblur() 事件
- history.back()在弹出窗口IE中不起作用
- 打开单个实例的弹出窗口IE
- 调用窗口.IE中的close抛出null或未找到对象错误