Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

139
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda