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

202
Views
Get all iframes in parent window having same origin from an iframe

I have a page in which I'm including iframes from two different domains i.e. like below

<!-- domain 1 frames -->
<iframe src="domain1/page1.html">
<iframe src="domain1/page2.html">

<!-- domain 2 frames -->
<iframe src="domain2/page1.html">

Now let's say I have the below javascript code in domain1/page1.html

var frames = window.parent.frames;

This will give me all iframes (iframe from domain 1 & domain 2) from parent windows. However, I want to get only iframes from domain 1. When I try to filter iframes from only domain 1 using the below code

var isSameOrigingIframe = window.location.host == window.parent.frames[i].location.host;

I receive a security exception (Cross-origin policy violation) as an iframe from domain 1 tries to access iframe domain 2.

My current solution relies on try-catch block as below

var isSameOrigingIframe = false;
try{
   isSameOrigingIframe = window.location.host == window.parent.frames[i].location.host;
}catch(e){
   isSameOrigingIframe = false;
}

The above solution works but is there is any safe way to get iframes only from the same domain? Or there is a better way to filter out iframes from the same domain.

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!