我该如何使用jQuery重新加载我的子窗口的父窗口?
在这种情况下不需要使用jQuery。
window.opener.location.reload(false);
您可以使用 window.opener, window.parent 或者 window.top来引用目标窗口,然后只需调用 reload
方法 (例如:window.parent.location.reload()
)。
但需要注意的是,如果您需要从最初打开的页面导航离开页面,则可能会遇到使用 window.opener
的问题,因为参考将丢失。
reload()
不是window
的方法。你指的是window.parent.location.reload()
,这个我在我的答案中已经提到了。 - Justin Johnsonparent.location.reload();
这应该可以工作。
如果你想简单地重新加载子窗口的父窗口: 下面的代码行就足够了。
opener.location.reload();
如果您想使用旧的或新的值重新加载带有查询字符串(请求)的父窗口,则以下代码将完成此工作。
if (opener.location.href.indexOf('?') > 0) {
var baseUrl = opener.location.href.substring(0, opener.location.href.indexOf('?'));
opener.location.href = baseUrl + "?param1=abc¶m2=123";
}
else {
opener.location.href = opener.location.href + "?param1=abc¶m2=123";
}
在上面的例子中,opener.location.reload();
是不必要的。
window.opener.location.reload()
window.close();
你可以使用以下方法重新加载父窗口位置:
window.opener.location.href = window.opener.location.href;
top.frames.location.reload(false);
window.parent.opener.location.reload();
对我有用。
防止先前的数据被重新提交。在Firefox和Safari中进行了测试。
top.frames.location.href = top.frames.location.href;
window.opener.location.reload(true);
对于某些版本的IE,这将无法正常工作,因此您可以设置一些延迟。
window.setTimeout(window.opener.location.reload(true), 3000);