2013-02-25 86 views
0

我试图使登录窗体在iframe中打开。如果用户单击提交按钮时登录成功,我希望iframe关闭并将浏览器重定向到index.php。 问题是,我不知道如何从这一点关闭iframe。如何在成功登录时在父级关闭iframe?

下面是相关的iframe的代码,我有:

login.tmpl(HTML文件,其中的形式)

<div class="form_item submit_button"> 
    <button type="submit" name="submit">Login</button> 
</div> 

login.php中(其中i重定向到指数这是哪里我想我需要一些额外的代码以关闭IFRAME)

if (!$error) { 
     throw new RedirectBrowserException('index.php'); 
    } 

gallery.tmpl(其中的iframe被调用。不应该是很重要的,我认为)

<a class="fancybox iframe fancybox.iframe" href="login.php">Iframe Login</a> 

编辑。这里是我的jQuery代码(gallery.tmpl):

 $(document).ready(function() { 
      $(".fancybox").fancybox({ 
      padding : 0, 
      prevEffect : 'none', 
      nextEffect : 'none', 
      helpers : { 
       title : { 
        type: 'over' 
       }, 
       thumbs : { 
        width : 50, 
        height : 50 
       } 
      } 
      }); 
     }); 
     $(document).ready(function() { 
      $("a.iframe").fancybox({ 
      autoDimensions : false, 
      autoSize : false, 
      padding : 0, 
      width : 395, 
      height : 195, 
      type : 'iframe' 
      }); 
     }); 

回答

0

你可以相当重定向到的index.php从页面打开的fancybox(gallery.tmpl)。只需在您的fancybox自定义脚本添加的回调:

$(".fancybox").fancybox({ 
    afterClose : function(){ 
     // redirects to another file after closing 
     window.location.href = "index.php"; 
    } 
}); 

然后,里面loging.php你可以做到这一点,收于成功的fancybox:

<?php if (!$error) { ?> 
    <script>parent.jQuery.fancybox.close();</script> 
<?php }; ?> 
+0

谢谢。第二部分工程关闭fancybox,但第一部分废弃我的iframe并在主窗口中打开登录页面。我无法找到关于这个afterClose的东西的任何信息...我也尝试在login.php重定向后关闭iframe,在这种情况下,它重定向iframe首先索引,然后关闭它。 – Chemist 2013-03-06 00:08:49

0

就解决了这个问题。最后,这使它的工作:

if (!$error) { ?> 
    <script type="text/javascript"> 
    parent.$.fancybox.close(); //can use jQuery instead of $ 
    window.parent.location ='index.php';  
    </script> <?php 
    } 

因此,重定向的父母是我所缺失的,直到我想通了。我尝试着使用某种延迟,但没有奏效。