窗口弹出窗口关闭并在成功登录Facebook时刷新父页面

时间:2016-03-05 10:03:24

标签: javascript php jquery facebook codeigniter

我已经完成了登录社交网站的工作,但我遇到了如何关闭弹出窗口并在成功登录后刷新父页面的麻烦

这是我目前的方法(这可能对你没有帮助,但我只是想让你知道我已经完成了我的工作)这是我的JS:

    function PopupCenter(url, title, w, h) {  
        // Fixes dual-screen position                         Most browsers      Firefox  
        var dualScreenLeft = window.screenLeft != undefined ? window.screenLeft : screen.left;  
        var dualScreenTop = window.screenTop != undefined ? window.screenTop : screen.top;  

        width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;  
        height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;  

        var left = ((width / 2) - (w / 2)) + dualScreenLeft;  
        var top = ((height / 2) - (h / 2)) + dualScreenTop;  
        var newWindow = window.open(url, title, 'scrollbars=yes, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);  

        // Puts focus on the newWindow  
        if (window.focus) {  
            newWindow.focus();  
        }  
    }  

我的HTML:

<a href="<?php echo base_url()?>hauth/login/Facebook" target="popup"  onclick="PopupCenter('<?php echo base_url()?>hauth/login/Facebook','xtf','900','500');   return false;">

并确定用户是否已连接(位于Hauth /登录控制器上)

if ($service->isUserConnected())
{
    log_message('debug', 'controller.HAuth.login: user authenticated.');
    $user_profile = $service->getUserProfile();
    log_message('info', 'controllers.HAuth.login: user profile:'.PHP_EOL.print_r($user_profile, TRUE));
    $data['user_profile'] = $user_profile;
    $this->load->view('hauth/done',$data);
}
else // Cannot authenticate user
{
    show_error('Cannot authenticate user');
}

1 个答案:

答案 0 :(得分:0)

在您的视图页面中添加如下: -

 if($user_profile) echo '<script>window.close();
        window.opener.location.reload();</script>';