Refresh the Calling Window in javascript

I recently ran into an issue in which I had to reload the calling tab after the user interacts with a control on the new tab. After much Googling, I found this handy line of javascript:

window.opener.location.reload();

That was it. One simple line of code. I am against copying and pasting code without knowing what the it does, so let’s delve into it to better understand it.

window

This is the current window object in the DOM. From here you have access to everything you typically have access to, but when it is a tab and opened from another page, you have access to:

opener

which is a property that is a reference to the window that created it. You could feasibly make other changes to the calling tab’s DOM via this.

The other methods are self-explanatory: gets the current location, or URL, and reloads it. reload does the same thing as pressing F5 or selecting the refresh button in your browser.

Leave a comment