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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s