Answer the question
In order to leave comments, you need to log in
How to open two tabs by clicking on a link?
I want to open two new pages by clicking on the link. One page opens in a new window, the other - in the same. An example is here jakeweb.96.lt/example Does
n't work
in Safari. What could be the reason?
PS Code
<a href="https://www.youtube.com/" onclick="location.href='https://translate.google.com/';" target="_blank">
Click Me
</a>
Answer the question
In order to leave comments, you need to log in
<a href="http:/google.com" data-href2="https://translate.google.com/">Click</a>
var els = document.querySelectorAll("a");
for(var i = 0; i < els.length;i++)
els[i].addEventListener("click",function(){if(this.getAttribute("data-href2"))window.open(this.getAttribute("data-href2"));},false)
Well, look at your code carefully. You change the address of the current page twice.
document.querySelector("a").addEventListener("click", function() {
document.location.href = "https://youtube.com/";
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question