Amir Amiri
Amir Amiri

Reputation: 437

Prevent opening a link in new tab if the url has already opened in a tab

I have some links in the menu bar. I want if the user clicks on a link for example "http://example.com/Archive" and when this link is opened in a tab if user clicks again on that link again the browser focus on the previous opened tab. How can I do it with javascript? *the solution must support old Internet explorers too.

Upvotes: 2

Views: 848

Answers (2)

Deepak-MSFT
Deepak-MSFT

Reputation: 11335

for Internet Explorer, You can try to work with Window instead of tab. Because we cannot get tab id in IE.

Example:

<!DOCTYPE html>
<html>
<body>


<button onclick="myFunction()">click here...</button>

<script>
function myFunction() {
  var myWindow = window.open("", "demo", "width=200,height=100");
  myWindow.document.write("<p>A new window!</p>");
  myWindow.focus();
}
</script>

</body>
</html>

Upvotes: 1

lx1412
lx1412

Reputation: 1200

Give every link a unique target.

<a href="http://example.com/Archive" target="uniqueTarget">somelink</a>

Or

window.open('http://example.com/Archive','uniqueTarget')

Upvotes: 1

Related Questions