Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

141
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!