jQuery Colorbox 在关闭时重新加载父页面
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5715445/
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
Colorbox reload parent page on close
提问by Lucas
My issue is that I need a colorbox to reload the parent page on close.
我的问题是我需要一个颜色框来在关闭时重新加载父页面。
This is what I have:
这就是我所拥有的:
$(".example").colorbox({
onClosed:function(){
parent.location.reload();
}
});
Colorbox loads fine, but doesn't refresh the parent page on close. Any Ideas?
Colorbox 加载正常,但在关闭时不会刷新父页面。有任何想法吗?
回答by CoolEsh
Use window.location.reload();
or window.location = window.location;
instead of parent.location.reload();
使用window.location.reload();
或window.location = window.location;
代替parent.location.reload();
回答by Adway Lele
A bit delayed, but I've got another answer. You can send the code to reload window from the target page that gets loaded in colorbox.
有点延迟,但我有另一个答案。您可以将代码发送到从在 colorbox 中加载的目标页面重新加载窗口。
I was using the colorbox for login/how_it_works/faqs & few other functions. I wanted my parent page to reload only in case of 'login'. So, in response to login form, I sent the following code:
我使用 colorbox 登录/how_it_works/faqs 和其他一些功能。我希望我的父页面仅在“登录”的情况下重新加载。因此,为了响应登录表单,我发送了以下代码:
<script type="text/javascript">
window.parent.location.reload();
</script>
'window' is colorbox window. I'm asking its parent (browser window) to reload.
'window' 是颜色框窗口。我要求它的父级(浏览器窗口)重新加载。
回答by Aart den Braber
Or just use
或者只是使用
<input type="submit" onclick="parent.location.reload()" value="Save" name="submit"/>
I prefer this one over Lucas's solution, because you can also easily create
我更喜欢这个而不是 Lucas 的解决方案,因为你也可以轻松地创建
<input type="button" onclick="javascript:parent.$.colorbox.close()" value="Cancel" />
without it reloading the entire page.
没有它重新加载整个页面。
回答by sabiland
Here is my generic colorbox-opening-function:
这是我的通用 colorbox-opening-function:
It can:
它可以:
- Reload the page after closing
- Reload it-self (+ with some custom Ajax URL)
- Load another HTML
- IMPORTANT -> these actions happen when you MANUALLY close colorbox:
- Setup global variables appropriately
- $.colorbox.close();
- 关闭后重新加载页面
- 重新加载它自己(+ 一些自定义的 Ajax URL)
- 加载另一个 HTML
- 重要 -> 当您手动关闭颜色框时会发生这些操作:
- 适当地设置全局变量
- $.colorbox.close();
Also:
还:
- Focus a custom HTML element after load
- 加载后聚焦自定义 HTML 元素
The main point is, you should have (but of course if you know what you're doing) some few GLOBAL JavaScript variables and that's it.
重点是,您应该拥有(当然,如果您知道自己在做什么)一些 GLOBAL JavaScript 变量,仅此而已。
function showActionForColorBox(
_url,
_forFocus
) {
_url = fixURLWithMasterServerPrefix(_url);
$.colorbox(
{
scrolling: false,
href: _url,
onLoad: function () {
idColorboxAjaxIndect1.appendTo($('#cboxOverlay'));
idColorboxAjaxIndect2.appendTo($('#cboxOverlay'));
idColorboxAjaxIndect3.appendTo($('#cboxOverlay'));
idColorboxAjaxIndect4.appendTo($('#cboxOverlay'));
return;
},
onComplete: function () {
if (_forFocus) {
var c = $('#' + _forFocus);
if (c.length) {
c.focus();
}
}
return;
},
onCleanup: function () {
// TODO: ?
return;
},
onClosed: function () {
abortAllAsyncAjaxRequests();
if (shouldReloadPageAfterColorBoxAction) {
shouldReloadPageAfterColorBoxAction = false; // NOTE: To be sure: Reset.
reloadWholePage();
}
else if (cbEBillsActionReloadPopup) {
cbEBillsActionReloadPopup = false;
// NOTE: WE HAVE AN OPTION TO RELOAD COLORBOX WITH CUSTOM URL !
showActionForColorBox((cbActionReloadPopupCustomURL !== '' ? cbActionReloadPopupCustomURL : _url));
cbActionReloadPopupCustomURL = '';
}
else if (cbShouldLoadAnotherContentAfterClosed) {
cbShouldLoadAnotherContentAfterClosed = false;
$.colorbox({ html: setupContentForcbShouldLoadAnotherContentAfterClosed });
setupContentForcbShouldLoadAnotherContentAfterClosed = '';
}
return;
}
}
);
return;
}
回答by Noyal Joy
$(document).bind('cbox_closed', function(){
location.reload();
});
The above code is for colorbox default close (x) button.
上面的代码用于 colorbox 默认关闭 (x) 按钮。
If you have your own close button then try like this:
如果您有自己的关闭按钮,请尝试如下操作:
$('#id').click(function(){
location.reload();
});
回答by Greeed
function __colorbox_onClose(e) {
$.fn.colorbox.close();
return false;
}
$.fn.colorbox.close(); - Closes colorbox manually
return false; - reloads/Autopostbac's form from which you called colorbox