71

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

Chris Forrence
  • 10,042
  • 11
  • 48
  • 64

12 Answers12

106

No jQuery is necessary in this situation.

window.opener.location.reload(false);

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

Travis
  • 12,001
  • 8
  • 39
  • 52
ChaosPandion
  • 77,506
  • 18
  • 119
  • 157
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.

Justin Johnson
  • 30,978
  • 7
  • 65
  • 89
  • +1 The marked answer used window.opener (which I understand why that is the preferred way), but I only had luck w/ window.top – Rikon Jun 08 '12 at 15:39
  • 1
    If the child window was an iframe, you can use: window.parent.reload(); or window.parent.location.href='abc.html'; – shasi kanth Oct 16 '12 at 07:44
  • `reload()` is not a method of `window`. You mean `window.parent.loacation.reload()`, which I have in my answer. – Justin Johnson Oct 19 '12 at 01:37
16
parent.location.reload();

This should work.

Adem Büyük
  • 563
  • 7
  • 15
  • And set the optional parameter to true to bypass the browser cache. e.g. parent.location.reload(true); ref. https://www.w3schools.com/jsref/met_loc_reload.asp – Zeek2 Aug 02 '18 at 12:46
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.

ARr0w
  • 1,701
  • 15
  • 31
4

This working for me:

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

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

Rajesh Kumar
  • 602
  • 6
  • 20
3

You can reload parent window location using :

window.opener.location.href = window.opener.location.href;
Raju Ram
  • 943
  • 9
  • 15
2
  top.frames.location.reload(false);
CG_DEV
  • 788
  • 7
  • 7
1

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

top.frames.location.href = top.frames.location.href;
CodeChap
  • 4,132
  • 6
  • 30
  • 40
1
window.parent.opener.location.reload();

worked for me.

vc 74
  • 37,131
  • 7
  • 73
  • 89
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);
Ramin eghbalian
  • 2,348
  • 1
  • 16
  • 36
0

this will work

window.location.assign(window.location.href);
Avnish Tiwary
  • 2,188
  • 22
  • 27
0

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

See details here

LukeSolar
  • 3,795
  • 4
  • 32
  • 39