Open a new tab and redirect the current tab to another page on a Javascript link

Asked

Viewed 2,579 times

-4

I need to do, in javascript, a link that opens a page in a new tab and redirects the current page to another link.

1 answer

1

HTML:

<a href="https://www.google.com" target="_blank" id="xx">abrir em nova janela</a>

JS:

document.getElementById('xx').addEventListener('click', function(){
  location.replace('https://answall.com');
});
  • Sorry to ask ,I am completely layman, what is xx ?

  • xx is the name of id. Ids are a way to identify an element, and should be UNIQUE for each element.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.