W
W
WhatIsHTML2017-10-02 20:37:41
JavaScript
WhatIsHTML, 2017-10-02 20:37:41

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

2 answer(s)
T
twobomb, 2017-10-02
@WhatIsHTML

<a href="http:/google.com" data-href2="https://translate.google.com/">Click</a>

Onload
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)

P
profesor08, 2017-10-02
@profesor08

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 question

Ask a Question

731 491 924 answers to any question