Reload parent window from child window
Asked Answered
R

12

71

How can I reload my child window's parent using jQuery?

Rosary answered 23/8, 2009 at 7:39 Comment(0)
M
108

No jQuery is necessary in this situation.

window.opener.location.reload(false);

https://developer.mozilla.org/en-US/docs/Web/API/Window

Madaih answered 23/8, 2009 at 7:41 Comment(5)
Yep, just fixed that. Thanks for the explanation.Madaih
It does take an argument - you can pass in true to force reload (i.e. ignore cache)Woodworker
The Mozilla reference site mentions this. I wonder if it is browser specific.Madaih
Even if the argument is non-standard, it will be ignored (w3.org/TR/Window/#location-methods), so there's no harm in using it unless you want the default behaviour.Handout
Not working in chrome: Uncaught TypeError: Cannot read property 'location' of nullZipporah
T
25

You can use window.opener, window.parent, or window.top to reference the window in question. From there, you just call the reload method (e.g.: window.parent.location.reload()).

However, as a caveat, you might have problems with window.opener if you need to navigate away from the originally opened page since the reference will be lost.

Tropical answered 23/8, 2009 at 8:39 Comment(3)
+1 The marked answer used window.opener (which I understand why that is the preferred way), but I only had luck w/ window.topDiplostemonous
If the child window was an iframe, you can use: window.parent.reload(); or window.parent.location.href='abc.html';Aporia
reload() is not a method of window. You mean window.parent.loacation.reload(), which I have in my answer.Tropical
S
17
parent.location.reload();

This should work.

Slant answered 20/4, 2017 at 8:33 Comment(1)
And set the optional parameter to true to bypass the browser cache. e.g. parent.location.reload(true); ref. w3schools.com/jsref/met_loc_reload.aspUsury
A
6

if you want to simply reload the parent window of child window: This line code below is enough for that.

opener.location.reload(); 

if you want to reload parent window with query string (request) with old or new values. Following code will do the work.

if (opener.location.href.indexOf('?') > 0) {
      var baseUrl = opener.location.href.substring(0, opener.location.href.indexOf('?'));
      opener.location.href = baseUrl + "?param1=abc&param2=123";
}
else {
      opener.location.href = opener.location.href + "?param1=abc&param2=123";
}

this opener.location.reload(); is not required in above example.

Annamaeannamaria answered 5/10, 2018 at 11:43 Comment(0)
G
5

This working for me:

  window.opener.location.reload()
  window.close();

In this case Current tab will close and parent tab will refresh.

Grof answered 26/4, 2017 at 8:34 Comment(0)
I
3

You can reload parent window location using :

window.opener.location.href = window.opener.location.href;
Iconoclasm answered 7/6, 2013 at 5:23 Comment(0)
H
2
  top.frames.location.reload(false);
Hagiology answered 3/5, 2013 at 20:57 Comment(0)
I
1

Prevents previous data from been resubmitted. Tested in Firefox and Safari.

top.frames.location.href = top.frames.location.href;
Ian answered 15/9, 2014 at 20:20 Comment(0)
O
1
window.parent.opener.location.reload();

worked for me.

Obelia answered 6/4, 2016 at 6:43 Comment(0)
A
1

This will work for refresh parent window from child window

window.opener.location.reload(true);

for some version of IE this will not work so you can set some delay

window.setTimeout(window.opener.location.reload(true), 3000);
Adorn answered 27/2, 2020 at 14:41 Comment(0)
A
0

this will work

window.location.assign(window.location.href);
Asoka answered 25/8, 2017 at 14:8 Comment(0)
S
0

For Atlassian Connect Apps, use AP.navigator.reload();

See details here

Syringomyelia answered 22/5, 2020 at 7:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.