登录与Facebook弹出窗口不关闭,我的登录后页面在弹出窗口中打开

时间:2013-09-18 04:12:39

标签: facebook codeigniter popup

当facebook弹出窗口打开后,输入电子邮件和密码后;弹出窗口没有关闭。成功登录后应加载的页面在弹出窗口中加载。如果我手动关闭此弹出窗口并刷新父页面,那么一切正常。

我在javascript中使用过windows.close和window.opener.location.reload函数,但它似乎无法正常工作

我正在使用codeigniter:

我的控制器

    <?php
class Landing extends CI_Controller {
    private $user = null;
    public function __construct()
    {
        parent:: __construct();
        parse_str($_SERVER['QUERY_STRING'], $_REQUEST);     
        //print_r($this->session->all_userdata());
        $redirect_url = (isset($_GET['redirect_url'])) ? $_GET['redirect_url'] : '';
        if($this->session->userdata('loginStatus')) {
            if($redirect_url && $redirect_url !=='') {
                redirect($_GET['redirect_url']);
            } else {
                redirect('home');
            }
        }


        $this->load->library('fb_api/facebook', array("appId" => $this->config->item('appId') , "secret" => $this->config->item('secret')));
        $this->user = $this->facebook->getUser();

    }

    public function index(){
        if (isset($_REQUEST['state']) && isset($_REQUEST['code'])) {
                echo "<script>window.close();window.opener.location.reload();</script>";
            } else {
                // load page
            }

        if ($this->user) {
          try {

视图:

<script type="text/javascript">
    var baseUrlJs = '<?php echo base_url()?>';
    var sessMemLayer = "<?=$this->session->userdata('loginStatus')?>";
    <?php if ($loginFbUrl) { ?>
    var newwindow;
    var intId;
    function loginFB(){
        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),
             width    = 500,
             height   = 270,
             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('<?=$loginFbUrl?>','Login_by_facebook',features);

       if (window.focus) {newwindow.focus()}
      return false;

    }

    <?php } ?>

</script>

请帮忙 感谢

1 个答案:

答案 0 :(得分:0)

找到了解决方案:

    <?php
<script>
window.opener.location.reload();
window.close();
</script>

return $this->renderText('<script>opener.location = "' . $url . '";window.close();     </script>'); 
?>