2010-12-05 13 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指向您的父窗口應刷新頁面。