2010-12-05 49 views

回答

3

好像你可以做这个你自己?

当用户点击'通过Facebook登录' - 使用JS来弹出一个位置为/ auth/facebook的窗口。 '回调'将在相同的窗口中返回到/ auth/callback。一旦你完成了回调的工作,关闭当前窗口并刷新父项?

+0

谢谢cory!是/ auth/callback处理各种网络的通用函数? – 2010-12-06 04:53:32

+0

得到它的工作,谢谢! = D – 2010-12-06 12:07:36

15
var newwindow; 
function login(provider_url, width, height) { 
    var screenX  = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft, 
     screenY  = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop, 
     outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth, 
     outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22), 
     left  = parseInt(screenX + ((outerWidth - width)/2), 10), 
     top   = parseInt(screenY + ((outerHeight - height)/2.5), 10), 
     features = ('width=' + width + ',height=' + height + ',left=' + left + ',top=' + top); 

     newwindow = window.open(provider_url, 'Login', features); 

    if (window.focus) 
    newwindow.focus(); 

    return false; 
} 

用'/ auth/facebook'或'/ auth/twitter'替换provider_url应该可以工作。

在回调网址,

<script type="text/javascript"> 
    window.opener.location = '<%= @redirect_to %>'; 
    window.close(); 
</script> 

您可以刷新页面,但是你想与@redirect_to指向您的父窗口应刷新页面。