Now I have a link
<a href="blabla" target="_blank">link</a>
However, this always open up a new tab. I want the following effect
- If the user already has a tab with the same URL, reuse that tab, and refresh if possible
- Otherwise, open a new tab
How can I achieve this using JavaScript?
It’s OK if there’re only some browser-specific methods, so users of browsers without corresponding support will “fallback” to the always-new-tab way.
You can set specific window’s name, in order to open reuse the tab. The problem is, as far as the href will be the same, it won’t be reloaded. So you can’t obtain the
refreshpart easily.So, for instance, you can have:
In JS, you can actually obtain the same, using
window.open. You could also use the url astarget, so that you don’t need to specify manually:You could also generalize, and add a click listener to the document, in order to open some links in this way. Something like:
If the page are on the same domain, at this point you could probably trying to do an empiric refresh of the page as well.