2010-07-17 141 views
13

我想在关闭Fancy Box弹出框时刷新父页。我在弹出窗口中有一个登录页面,所以我需要刷新父页面以在Fancy Box关闭时显示新的登录状态。Fancy Box - 关闭iframe弹出窗口时如何刷新父页面?


我可以得到它没有的IFRAME代码工作:

<script type="text/javascript"> 
$(document).ready(function() { 
    $("a.iframeFancybox1").fancybox({ 
    'width': 800, 
    'height': 450, 
    'onClosed': function() { 
    parent.location.reload(true); 
    ;} 
    }); 
}); 
</script> 

但我不能让它使用iframe代码工作:

<script type="text/javascript"> 
$(document).ready(function() { 
    $('a.iframeFancybox1').fancybox({ 
    'width': 800, 
    'height': 450, 
    'type' : 'iframe' 
    'onClosed': function() { 
    parent.location.reload(true); 
    ;} 
    }); 
}); 
</script> 

问题是这样做的:

'type' : 'iframe'
 

只要我添加该行,弹出窗口停止工作。

任何人都可以提出一个解决方案,我怎样才能得到一个iframe弹出花式框,并仍然得到父页刷新时,框关闭? 谢谢!

+1

你只是缺少“IFRAME”后一个逗号? – user11977 2010-07-17 02:01:51

+0

谢谢smerriman!是。我错过了一个逗号。接得好。 我修正了这个问题,但我仍然无法得到这个关闭重新加载页面。 还有什么想法? – dave 2010-07-17 04:59:30

回答

2

对我来说,下面的代码工作正常:

$("a.ic-edit").fancybox({ 
      'width'  : '65%', 
      'height' : '85%', 
      'autoScale'  : false, 
      'titleShow' : false, 
      'transitionIn' : 'no', 
      'transitionOut' : 'no', 
      'scrolling'  : 'no', 
      'type'   : 'iframe', 
      onCleanup : function() { 
       return window.location.reload(); 
      } 
     }); 

我不能说完全是,但也许在使用“onCleanup”的原因(其实我没有尝试使用onClosed)。

10
$(".fancybox").fancybox({ 
      'width'    : '75%', 
      'height'   : '65%', 
      'autoScale'   : false, 
      'transitionIn'  : 'none', 
      'transitionOut'  : 'none', 
      'type'    : 'iframe', 
      'hideOnOverlayClick': false, 
      'onClosed'   : function() { 
            parent.location.reload(true); 
            } 
     }); 
0

当在'location.reload'中使用示例时,会得到一个浏览器弹出窗口,让您知道它需要重新加载页面。我点击了一个按钮来刷新页面,并没有警告弹出窗口。

$(".addDoc").colorbox({ 
    iframe: true, 
    width: "550px", 
    height: "230px", 
    'onClosed': function() { 
     $("#btnContSave").click(); 
    } 
}); 
+0

OP正在使用fancybox ...而不是colorbox,所以你的例子中的选项将无法与fancybox – JFK 2012-03-16 20:04:58

+0

啧啧谢谢...你甚至在否定之前尝试过吗? – Greg 2012-03-19 14:41:41

+0

你有没有试过fancybox? ;) – JFK 2012-03-19 18:48:15

28
$(".fancybox").fancybox({ 
    type: 'iframe', 
    afterClose: function() { // USE THIS IT IS YOUR ANSWER THE KEY WORD IS "afterClose" 
     parent.location.reload(true); 
    } 
}); 

或者:

转到您的jquery.fancybox.js文件和走线是这个样子,并添加parent.location.reload(true);

afterClose: function (opts) { 
    if (this.overlay) { 
     this.overlay.fadeOut(opts.speedOut || 0, function() { 
      $(this).remove(); 
      parent.location.reload(true); 
     }); 
    } 
    this.overlay = null; 
} 
+0

+1“有一个不错的项目”..嘿嘿。 – Spudley 2012-07-17 21:51:56

+3

用这种方法,你正在改变所有Fancybox的行为,这在大多数情况下可能不适用。 – Raptor 2012-10-10 10:36:18

+0

+1这适用于我的问题 – Seeker 2013-03-14 13:51:53

1
'onClosed': function() { 
parent.location.reload(true); 
;} // <----is it ok if you have an extra ';' here? 
+0

不会。这会给出一个js错误。 – Greg 2013-05-10 17:44:02

1

围绕着t的工作Ø避免POSTDATA警告当你关闭的iFrame

1)请创建形式:

花式版本为2.xx:

<form name="RefreshForm" method="post" action="" > 
<input name="Name1" value="Value1" type="hidden" /> 
<input name="DatafromPost1" value="ValuefromPOST1" type="hidden" /> 
<input name="DatafromPost2" value="ValuefromPOST2" type="hidden" /> 
</form> 

2)在你的想象盒的末尾添加此行

afterClose : function() { 
setTimeout('document.RefreshForm.submit()',1000); } 

花式版本1.3.x的

 onClosed : function() { 
setTimeout('document.RefreshForm.submit()',1000); } 

1000 = 1秒。

1

链接刷新:

jQuery(function($){ 
    $('#refresh').click(function() 
     {  
      parent.location.reload(); 
    }); 
}); 

<a href="#" id="refresh">refresh</a> 

你能给:

setTimeout(function() { 
      parent.location.reload(); 
     }, 1000); 

或条件,例如,

<script> 
if(formSend == true){ 
setTimeout(function() { 
       parent.location.reload(); 
      }, 1000); 
} 
</script> 
-1

'onClosed':函数(){parent.location。重新加载(真); }

1

你只需要写两行关闭fancybox,并在关闭后重新加载打开你的fancybox的父页面。

有一两件事要声明的是,如果你将与window.opener它不会作为的fancybox工作不被视为父的子窗口,当谈到window.opener尝试

还有一事情是,window.opener不会用于Windows Phone和IE,因为IE已经很愚蠢。

<script type="text/javascript"> 
parent.$.fancybox.close(); 
     parent.location.reload(true); 
</script> 
1

除了明显的缺失,你说你已经修复了IMO这不是一个fancybox问题,而是一个父刷新问题。

我发现获得一个框架的父母来重新加载是一个挑战,因为有多种方法可以“理论上”实现这一点,但“大多数”只是不实际工作,更糟糕的是,实际上并没有似乎是我测试过的网页浏览器引发的任何错误。

这里是代码在Chrome,FF,IE浏览器对我的作品还有:

afterClose: function(){ 
    parent.location.href = parent.location.href; 
}, 

这基本上是说设置父HREF到不管它目前是在一个页面刷新的效果的结果。试试看,它应该工作得很好。

事实上行:

parent.location.href = parent.location.href; 

可以与帧被使用(当然从母体)或无帧简单地刷新网页。 HTH。

0

刷新或重新加载关闭在Shopify

我就是用这个Shopify上使用的fancybox的形式,但这个将在其他也

jQuery(".add-device").fancybox({ 
    maxWidth : 970, 
    maxHeight : 700, 
    fitToView : false, 
    width  : '90%', 
    height : '90%', 
    autoSize : false, 
    closeClick : false, 
    openEffect : 'none', 
    closeEffect : 'none', 
    beforeClose: function() { 
     device_has_subs = false; 
     $("#mac_address").prop("readonly", false); 
    }, 
    afterClose : function() { 
     window.location.reload(true); 
     } 
    }); 

只在这里工作afterClose正在玩任务 我们还可以写父母而不是窗口

afterClose : function() { 
    parent.location.reload(true); 
    } 

如果仅重置shopify形式然后,在某个时候shopify $( “表”)[0]。复位()不工作这么使用迭代,我们可以清空表格值

jQuery(".add-device").fancybox({ 
    maxWidth : 970, 
    maxHeight : 700, 
    fitToView : false, 
    width  : '90%', 
    height : '90%', 
    autoSize : false, 
    closeClick : false, 
    openEffect : 'none', 
    closeEffect : 'none', 
    beforeClose: function() { 
     device_has_subs = false; 
     $("#mac_address").prop("readonly", false); 

     var array_element = document.getElementById("form_id"); 
     if (array_element){ 

     for (i=0; i < array_element.length; i++){ 
      element = array_element[i].type.toLowerCase(); 
      switch(element){ 
       case "text": 
        array_element[i].value = ""; 
        break; 
       case "hidden": 
        array_element[i].value = ""; 
        break; 
       case "email": 
        array_element[i].value = ""; 
        break; 
       case "checkbox": 
        if(array_element[i].checked){ 
        array_element[i].checked = false; 
        } 
        break; 
       case "select-one": 
        array_element[i].selectedIndex = -1; 
        break; 
       case "select-multi": 
        array_element[i].selectedIndex = -1; 
        break; 
       default: 
        break; 
      } 

     } 

     } 

    }, 
    }); 

form_id的形式ID