dead pimp dead pimp - 10 months ago 55
jQuery Question

Refresh currently open tab with Javascript when a new tab is opened

Would it be possible to refresh the currently open tab when a new tab is opened by clicking a link in the first tab?
Basically, the end result would be like this: the first tab is open, a link on the page which is open in the first tab is clicked (with middle mouse button or something similar to that, just to make it open in the second tab), link which was clicked is opened in the second tab and then the first tab is automatically refreshed. I hope that I explained it understandably. Note: I'm not designing my own website, I'm looking to make a plugin for the website with Greasemonkey.

Answer Source

Let's assume you have this link on your page:

<a href="" target="_new">Link which opens new tab and refreshes current one</a>

In js script you add this (assuming you are using jQuery, as you stated):

        // Open new tab - in old browsers, it opens a popup window$(this).attr('href'), '_blank');
        // reload current page

Please test it in all browsers, as in some browsers it may open the link as a popup window instead of a new tab.

As a fast test, open with F12 developer tools on Chrome, and write in console:'', '_blank');location.reload();