jQuery 提交后关闭 ColorBox iFrame
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2009973/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Close ColorBox iFrame after submit
提问by diEcho
I'm using jQuery ColorBox
to display a shopping cart item. When a user enters the quantity in the iFrame (opened with colorbox) and clicks on the submit button, I want the iFrame to be close and main window (parent) to be refreshed automatically.
我正在使用 jQueryColorBox
来显示购物车项目。当用户在 iFrame 中输入数量(用颜色框打开)并单击提交按钮时,我希望 iFrame 关闭并自动刷新主窗口(父窗口)。
I mean I want two things after submitting data on iFrame:
我的意思是在 iFrame 上提交数据后我想要两件事:
- iFrame closes automatically.
- Parent window getting refresh automatically.
- iFrame 自动关闭。
- 父窗口自动刷新。
Please help me out.
请帮帮我。
回答by nik
use this on the parent window while opening iframe:
打开 iframe 时在父窗口上使用它:
$(document).ready(function(){
$(".chpic").colorbox({width:"80%", height:"80%", iframe:true,
onClosed:function(){ location.reload(true); } });
});
and this to close the iframe inside iframe page:
这是关闭 iframe 页面内的 iframe:
parent.$.fn.colorbox.close();
回答by barsh
After the form is submitted in Frame 1, you can use the following JavaScript to reload the parent frame:
在第 1 帧提交表单后,您可以使用以下 JavaScript 重新加载父框架:
window.parent.location.reload(true);
回答by Amien
<form target="_top">
回答by Rohan4
open jquery.colorbox.js find these two pieces of code:
打开 jquery.colorbox.js 找到这两段代码:
$close.click(function () {
publicMethod.close();
});
$overlay.click(function () {
if (settings.overlayClose) {
publicMethod.close();
}
});
replace with these - note the addition of " window.location.reload();"
替换为这些 - 注意添加“window.location.reload();”
$close.click(function () {
publicMethod.close();
window.location.reload();
});
$overlay.click(function () {
if (settings.overlayClose) {
publicMethod.close();
window.location.reload();
}
});
回答by Lilla
Just simply simulate a click on the close button, like this:
只需简单地模拟点击关闭按钮,如下所示:
$("#cboxClose").click();
回答by karthik
Give form tag like this:
像这样给出表单标签:
<form target="_top">
then after submit:
然后提交后:
response.redirect("your form")
回答by jalalkhan121
If you want to stay on current page :
如果你想留在当前页面:
write the following code on parent page where colorbox is applied.
$(document).ready(function(){ $(".tu_iframe_800x600").colorbox({width:"80%", height:"100%", iframe:false }); });
and the following code on your current page where you want to close colorbox
parent.$.fn.colorbox.close();
在应用 colorbox 的父页面上编写以下代码。
$(document).ready(function(){ $(".tu_iframe_800x600").colorbox({width:"80%", height:"100%", iframe:false }); });
以及您要关闭颜色框的当前页面上的以下代码
parent.$.fn.colorbox.close();
Note: please replace .tu_iframe_800x600
with your html class on which the colorbox is called...
注意:请替换.tu_iframe_800x600
为您在其上调用颜色框的 html 类...
回答by Nick
If you're using Drupal 7, you may need to use the following alternative:
如果您使用的是 Drupal 7,则可能需要使用以下替代方法:
parent.jQuery.colorbox.close();
In D7, the $.fn seems to be replaced by the jQuery object.
在 D7 中,$.fn 似乎被 jQuery 对象取代。
I simply setup a menu callback which simply returned this:
我只是设置了一个菜单回调,它简单地返回了这个:
return <<<EOF
<script type="text/javascript">
<!--//--><![CDATA[//><!--
parent.jQuery.colorbox.close();
//--><!]]>
</script>
EOF;
Seemed to work fine for me :)
对我来说似乎工作正常:)