2012-10-09 38 views
1

我在這裏使用了Chris Heald的答案:「http://stackoverflow.com/questions/4491433/turn-omniauth-facebook-login-into-a-popup」,它的工作完美。Rails Facebook OAuth Popup JS

一個問題是在重定向。我使用Devise和Oauth進行Facebook登錄 - 我希望彈出窗口在登錄後關閉,用戶在登錄/註冊後重定向到適當的頁面。

由於某種原因,現在,彈出窗口中會載入正確的路徑,並且彈出窗口不會關閉。我想我錯過了一些非常基本的東西。有任何想法嗎?我是一個總JS新手!

JS的彈出窗口:

function popupCenter(url, width, height, name) { 
    var left = (screen.width/2)-(width/2); 
    var top = (screen.height/2)-(height/2); 
    return window.open(url, name, "menubar=no,toolbar=no,status=no,width="+width+",height="+height+",toolbar=no,left="+left+",top="+top); 
    } 

    $("a.popup").click(function(e) { 
    popupCenter($(this).attr("href"), $(this).attr("data-width"), $(this).attr("data-height"), "authPopup"); 
    e.stopPropagation(); return false; 
}); 

JS對重定向:

if(window.opener) { 
    window.opener.location = <%= after_sign_in_path %>; 
    window.close() 
    } 

回答

0

你確定你的after_sign_in_path是在引號?你可能會想,而不是嘗試:

window.opener.location = "<%= after_sign_in_path %>" 

我懷疑是不是關閉窗口,因爲在執行該行之前有一個JavaScript錯誤。