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

199
Views
IFRAME does not load all links in the order, but only the last one in loop

I have an array of nodes in Drupal CMS. I need to visit link in iframe, change some fields, save and go to another link inside my loop. The problem is: only last link is loading in iframe, when I run script in debug mode, iframe do not load links and iframe.contentWindow.document.readyState is loading.

When I use iframe.addEventListener('load', ...) it only triger the last link

So I need something like this

for(let i = 0; i < links.length; i++) {
    iframe.contentWindow.location.href = links[i]
    //when iframe is fully loaded and webpage is available
    change fields in iframe web page
    save changes
}  

I want to run this script and watch how each link loads, changes and saves

This is what I tried

const snippetMainContainer = document.createElement('div')
const snippetPageView = document.createElement('iframe')
snippetPageView.id = "snippetIframe"
const snippetUrl = document.createElement('input')

snippetMainContainer.append(snippetUrl)
snippetMainContainer.append(snippetPageView)

document.querySelector('body').appendChild(snippetMainContainer)

snippetPageView.setAttribute('src', `https://domen.com`)


function changePage() {
    const url = snippetPageView.contentWindow.location.href
    snippetUrl.value = url
}

snippetPageView.addEventListener('load', () => {
    changePage()
})


const nodeIdStr = `6001
5996
5296
5291`


const nodeIdArr = nodeIdStr.split('\n')


async function startEditNodes () {
    let nodeLink = ''
    for(let i = 0; i < nodeIdArr.length; i++) {
        nodeLink = `https://domen.com/node/${nodeIdArr[i]}/edit`
      
        snippetPageView.contentWindow.location.href = nodeLink 
        editNode()
    }
}

async function editNode () {
    // console.log(`nodeLink: ${link}`)

    const buyNowFusepump = snippetPageView.contentWindow.document.getElementById('edit-field-product-fusepump-wrapper')
    const buyNowLink = snippetPageView.contentWindow.document.getElementById('edit-field-product-buy-link-wrapper')
    const firstTab = snippetPageView.contentWindow.document.querySelector('.horizontal-tab-button-0 a')
    const saveBtn = snippetPageView.contentWindow.document.getElementById('edit-submit')

    if(firstTab) {
        firstTab.click()
    }

    snippetPageView.contentWindow.scrollTo(0,600)
    
    buyNowFusepump ? await editInput(buyNowFusepump) : console.log('Fusepump absent')
    buyNowLink ? await editInput(buyNowFusepump) : console.log('Buy now link absent')
    saveBtn ? saveBtn.click() : console.log('saveBtn absent')
}


async function editInput(node) {
    const nodeInput = node.querySelector('input')
    nodeInput.value = nodeInput.value + 'E'
}

startEditNodes ()
about 4 years ago · Juan Pablo Isaza
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!