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

111
Views
How would you get a src from an iframe within an iframe?

I have some code that in short, is opening an iframe (let's call it iframe1) to view a pdf file, and that pdf is being shown in an iframe itself (let's call it iframe2), I would like to be able to get the source of the iframe2 that is within an iframe1 that would be opened so that the iframe1 itself is just the src of the pdf iframe2 and not 2 different iframes. The Url's are very different.

what is the best way to do this?

I have an open_iframe function that looks something like

function open_iframe(url) {
    return '<iframe id="iframe" src="' + url + '" width=100% height=100% frameborder="0" allowfullscreen></iframe>';
}

and I am writing another function that is

function find_file_url(url) {
    let iframe = this.open_iframe(url);
    return iframe.contentWindow.document.getElementsByTagName('iframe')[0].src;
}

I also have Jquery available to use as well.

Is this something that's possible?

Is there a better approach?

Thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

have you attached the iframe object to your dom? In this the html tag for "iframe" instead of creating a html string , you can create the dom iframe object directly and assign attributes to them and then parse it further. As Barmar said until then it would considered as just a html string. .document.getElementsByTagName('iframe') will be a null element as it is not attached to document object.

about 4 years ago · Juan Pablo Isaza Report

0

You might try document.domain = "site.com" , I'm dealing with similar issue. This will ensure they are in the same domain

Also you can use iframe.contentWindow and iframe.contentDocument scripting to communicate inside for the nested frame.

also assign onload, errorOnload to the attributes for console tracking

iFrame onload JavaScript event

https://javascript.info/cross-window-communication

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!