Fancy Box – 如何在关闭iframe弹出时刷新父页面?
我想在关闭Fancy Box弹出框架时刷新我的父页面。 我在弹出窗口中有一个登录页面,所以当Fancy Box关闭时,我需要刷新父页面以显示新的登录状态。
我可以在没有iFrame代码的情况下使用它:
$(document).ready(function() { $("a.iframeFancybox1").fancybox({ 'width': 800, 'height': 450, 'onClosed': function() { parent.location.reload(true); ;} }); });
但我无法使用iFrame代码:
$(document).ready(function() { $('a.iframeFancybox1').fancybox({ 'width': 800, 'height': 450, 'type' : 'iframe' 'onClosed': function() { parent.location.reload(true); ;} }); });
问题与这条线有关:
'type' : 'iframe'
一旦我添加该行,弹出窗口就会停止工作。
任何人都可以建议一个解决方案,我如何在Fancy Box中弹出iframe
,并在框关闭时仍然可以刷新父页面? 谢谢!
$(".fancybox").fancybox({ type: 'iframe', afterClose: function () { // USE THIS IT IS YOUR ANSWER THE KEY WORD IS "afterClose" parent.location.reload(true); } });
或者:
转到你的jquery.fancybox.js文件并转到第1380行看起来像这样并添加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; }
$(".fancybox").fancybox({ 'width' : '75%', 'height' : '65%', 'autoScale' : false, 'transitionIn' : 'none', 'transitionOut' : 'none', 'type' : 'iframe', 'hideOnOverlayClick': false, 'onClosed' : function() { parent.location.reload(true); } });
对我来说,下一个代码工作正常
$("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)。
除了显而易见的缺失,你说你已经修复了IMO,这不是一个fancybox问题,而是一个父刷新问题。
我发现要让一个框架的父级重新加载是一个挑战,因为有多种方法可以“理论上”实现这一点,但“大多数”根本不能在实践中工作,更糟糕的是,实际上似乎没有我测试过的Web浏览器引发的错误。
这是适用于Chrome,FF,IE的代码:
afterClose: function(){ parent.location.href = parent.location.href; },
这基本上表示将父href设置为当前的任何内容,这实际上会导致页面刷新。 尝试一下,它应该运作良好。
实际上这行:
parent.location.href = parent.location.href;
可以与框架(当然来自父级)或没有框架一起使用来简单地刷新网页。 HTH。
'onClosed': function() { parent.location.reload(true); ;} // <----is it ok if you have an extra ';' here?
关闭iFrame时,要避免出现POSTDATA警告
1)请创建表格:
2)在你的Fancy-Box的末尾添加这些行:
花式2.xx
afterClose : function() { setTimeout('document.RefreshForm.submit()',1000); }
花式ver 1.3.x
onClosed : function() { setTimeout('document.RefreshForm.submit()',1000); }
1000 = 1秒。
链接刷新:
jQuery(function($){ $('#refresh').click(function () { parent.location.reload(); }); }); refresh
你可以给:
setTimeout(function () { parent.location.reload(); }, 1000);
或条件,例如,
您只需要写两行来关闭fancybox,然后关闭以重新加载已打开fancybox的父页面。
需要注意的一件事是,如果你将使用window.opener尝试它,它就不会起作用,因为当涉及到window.opener时,fancybox不会被视为父窗口的子窗口。
还有一件事是window.opener不能用于Windows手机以及IE,因为IE已经很愚蠢了。
当使用带有’location.reload’的示例时,您会看到一个浏览器弹出窗口,让您知道它需要重新加载页面。 我点击了一个按钮点击刷新页面,没有警告弹出窗口。
$(".addDoc").colorbox({ iframe: true, width: "550px", height: "230px", 'onClosed': function() { $("#btnContSave").click(); } });
使用Shopify中的fancybox关闭表单时刷新或重新加载
我在Shopify上使用它,但这也适用于其他
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中有时$(“form”)[0] .reset()不起作用,所以使用迭代我们可以清空表单值
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
‘onClosed’:function(){parent.location.reload(true); }