【问题标题】:Codeigniter: How to close fancybox and redirect the parent pageCodeigniter:如何关闭fancybox并重定向父页面
【发布时间】:2014-01-07 09:45:07
【问题描述】:

当点击登录按钮时,会出现一个包含登录表单的精美框。如果凭据正确,我想关闭花式框并将父页面重定向到主页。我的问题是,fancybox 没有关闭,重定向发生在 fancybox 内。此外,如果我选择取消,fancybox 应该关闭,但会出现错误($.fancybox 未定义)。我应该如何解决这个问题?顺便说一句,我正在使用 codeigniter、jquery 1.10.2 和 fancybox 2。提前致谢。

这是我的父页面:

<a id='login' href=<?php echo site_url('login'); ?>>Login</a>
<script type="text/javascript">
  $(document).ready(function() {
     $('#login').bind('click', function(e) {
        $.fancybox({ 
                'width': '35%', 
                'height': '40%', 
                'type': 'iframe', 
                'href': '<?php echo site_url("login")?>',
                'modal': true
        }); 
        return false;
    });
});
</script>

登录控制器

public function index() {
    $this->session->set_userdata('page', 'guest');
    $this->load->view('login_view');
}

public function checkFields() {
    $config = array(.....);
    $this->form_validation->set_rules($config); 

    if($this->form_validation->run() == false){
        $this->load->view('login_view');
    }
    else{
        $userType = $this->input->post('userType');
        redirect($userType.'/home');
    }       
}

登录查看花式框

<?php echo form_open('login/checkFields'); ?>   
<div id='login_view' style='width: 30%; margin-left: 35%'>
    <div class="panel panel-default loginClass">
        <div class="fancy">
            <table class="details"  style='font-size: 14px; width:100%; margin-top: 5%'>
                <tr>
                    <td>Username </td>
                    <td><input name="username" id="username" type="text" class="form-control" required autofocus></td>
                </tr>
                <tr>
                    <td>Password</td>
                    <td><input name="password" id="password" type="password" class="form-control" required> </td>
                </tr>

                <tr>
                    <td colspan="2" align="center"><a id="forgot_pw">Forgot Password?</a></td>
                </tr>
            </table>
            <center>
                <input type="submit" id="save" class="btn btn-default btn-primary" value="Login">
                <input type="button" id="cancel" class="btn btn-default" value="Cancel">
            </center>
        </div>
        <?php echo form_close(); ?>
    </div>

<script type="text/javascript">
$(document).ready(function() {
     $("#cancel").click(function() {
             $.fancybox.close();
     });
});
</script>

【问题讨论】:

    标签: jquery codeigniter redirect fancybox fancybox-2


    【解决方案1】:

    改变

    $.fancybox.close();
    

    parent.$.fancybox.close();
    

    或强制重定向到父页面

    parent.location.reload(true);
    

    这将重新加载父页面,并且fancybox被强制关闭。

    【讨论】:

    • 我也这样做了,但它仍然会产生这个错误:$.fancybox is undefined
    • 哦,做到了!登录后关闭fancybox并重定向父页面怎么样?
    • 在 fancybox 初始化中指定 afterClose 事件。 afterClose : function() { parent.location.reload(); } 这将在fancybox关闭时调用重新加载。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-31
    • 2011-04-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多