Turn omniauth facebook login into a popup

后端 未结 4 1234
醉梦人生
醉梦人生 2020-11-27 09:42

I\'m using the omniauth gem with rails and it works great with loging in users, but everytime it takes you to the fb login page then redirects you back. I was wondering if

4条回答
  •  一向
    一向 (楼主)
    2020-11-27 10:00

    Posting in case it helps others. I was using Chris Heald's answer but ran into trouble with the final bit of javascript closing any new window links. For example, if I posted a link to my site onto Facebook, when users clicked the link the new window would automatically close in Chrome because the condition only checks for "if(window.opener)"

    I ended up solving this with the use of a global variable (popupValue). There may be more elegant solutions but thought I'd share in case others hit the same issue:

    function popupCenter(url, width, height, name) {
     var left = (screen.width/2)-(width/2);
     var top = (screen.height/2)-(height/2);
     popupValue = "on";
     return window.open(url, name, "menubar=no,toolbar=no,status=no,width="+width+",height="+height+",toolbar=no,left="+left+",top="+top     );
    }
    
    $(document).ready(function(){
    $("a.popup").click(function(e) {
    popupCenter($(this).attr("href"), $(this).attr("data-width"), $(this).attr("data-height"), "authPopup");
    e.stopPropagation(); return false;
    });
    
    
    if(window.opener && window.opener.popupValue === 'on') {
     delete window.opener.popupValue;
     window.opener.location.reload(true);
     window.close()
    }
    });
    

提交回复
热议问题