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

138
Visualizações
open link search then close javascript

I try to open links, what i found, in a new window, then search for a text, and then close the new window. But its not working, the new window not closed, and the search also not working. and just open the first window.

 links = document.getElementsByTagName("a");
for (var i = 0, l = links.length; i < l; i++) {
  var link = links[i];
  if (link.href.indexOf("jooble") !== -1) {
        var newWindow = window.open(links[i].href);
        setTimeout(function(){ 
        console.log("5s")
         if (
                (newWindow.document.documentElement.textContent || newWindow.document.documentElement.innerText).indexOf('Jófogás') > -1) {
            console.log("Jófogás")
             
}   if(newWindow){
        newWindow.close();
    }
}, 5000);
                                            }
                                                }`
about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

unfortunately you cant's access to a window.open html contents.

var mywindow = window.open('https://www.wikipedia.org/', 'title', 'height=500, width=500'); 
console.log(mywindow.document) //you will get an empty html tag

You have to use a Web Scraper library like puppeteer for that

about 4 years ago · Juan Pablo Isaza Relatório

0

You not creating variable that your problem, place let before links and try again

let links = document.getElementsByTagName("a");
for (var i = 0, l = links.length; i < l; i++) {
  var link = links[i];
  if (link.href.indexOf("jooble") !== -1) {
        var newWindow = window.open(links[i].href);
        setTimeout(function(){ 
        console.log("5s")
         if (
                (newWindow.document.documentElement.textContent || newWindow.document.documentElement.innerText).indexOf('Jófogás') > -1) {
            console.log("Jófogás")
             
}   if(newWindow){
        newWindow.close();
    }
}, 5000);
                                        }
                                            }
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