jquery - Refresh currently open tab with Javascript when a new tab is opened -
would possible refresh open tab when new tab opened clicking link in first tab? basically, end result this: first tab open, link on page open in first tab clicked (with middle mouse button or similar that, make open in second tab), link clicked opened in second tab , first tab automatically refreshed. hope explained understandably. note: i'm not designing own website, i'm looking make plugin website greasemonkey.
let's assume have link on page:
<a href="http://server.com/url-to-second-tab" target="_new">link opens new tab , refreshes current one</a>
in js script add (assuming using jquery, stated):
$(document).ready(function(){ $('body').on('click','a',function(e){ e.preventdefault() // open new tab - in old browsers, opens popup window window.open($(this).attr('href'), '_blank'); // reload current page location.reload(); }) })
please test in browsers, in browsers may open link popup window instead of new tab.
as fast test, open f12 developer tools on chrome, , write in console:
window.open('https://google.com', '_blank');location.reload();
Comments
Post a Comment