Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

218
Visualizações
javascript: How to make all links on youtube to open in new tab

Example I have this youtube link which shows search results

https://www.youtube.com/results?search_query=himalayas

I am using firefox and its developer tools

I am trying to run this js script to make left click any link on the page to open in a new tab

code1

var e = document.createElement("base");
e.target = "_blank";
document.head.appendChild(e); 

Code2

var links = document.links;
for (var i = 0; i < links.length; i++) {
     links[i].target = "_blank";
}

Both of them add the target attribute

But after this script also i cannot open the link on new tab when left clicking

Any idea how can i do this

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You either have to

  1. remove the yt-simple-endpoint class that exists on the a href tags
    var links = document.links;
    for (var i = 0; i < links.length; i++) {
         links[i].classList.remove('yt-simple-endpoint')
         links[i].target = "_blank";
    }

If you remove the class it affects the styling, but you can always fix that by re-adding the styles.

or

  1. remove the click event listener that's attached to <ytd-app>

I don't think it's easy to remove event listeners in Firefox. You might be able to using Firebug. Chrome has getEventListeners, so you can run

const ytdApp = document.getElementsByTagName('ytd-app')[0]
ytdApp.removeEventListener('click', getEventListeners(ytdApp).click[0].listener)

var links = document.links;
for (var i = 0; i < links.length; i++) {
    links[i].classList.remove('yt-simple-endpoint')
    links[i].target = "_blank";
}
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda