Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6585593
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:41:00+00:00 2026-05-25T16:41:00+00:00

I’m comparing all iframes in my javascript, to see if one of them matches

  • 0

I’m comparing all iframes in my javascript, to see if one of them matches my element’s (an a -tag) body element. The problem I have is that the collection of iframes can sometimes change, because they are all generated by a framework. Hence sometimes I get “Access is denied” errors in IE8 and sometimes I don’t. I’m not referencing any external Iframes since all my Iframe are part of the framework and hence have same protocoll, port etc. This is the code I use to loop through the iframe collection:

var calculatedwidth = 0;
var calculatedheight = 0;

var searchbody = $(srcElement).closest('body');
//I store the Iframe-nodelist in var arrFrames
var arrFrames = document.getElementsByTagName("iframe");
LabelA1:
for(i = 0; i<arrFrames.length; i++){
    //console.log(i);
    //if(arrFrames[i].id != 'PeopleDetailsIframe'){

        if($(arrFrames[i].contentWindow.document.body).is(searchbody)){
        // This line is where the error occures normaly
               calculatedwidth = $(arrFrames[i]).offset().left;
               calculatedheight = $(arrFrames[i]).offset().top;
               break LabelA1;
        }
        else{
              //console.log("Forum Iframe not found");
            }
     }  
}  

I temporarily fixed my problem by including a break, to break out of the loop if my searched iframe is found. This works about 80% of the time my code is executed. But since the webpage is customizable, some users have responded that they get a javascript error when my code runs. Based on some research I did on the subject Cross-Domain scripting , Scripting with Iframe Collection, I learned that the Iframe collection is a live-collection? So this means that the collection is bound to change (sometimes) when I’m looping through it. So I assumed that this can cause 2 errors, an infinite loop or wrong index errors. I thought that storing the refrence to the iframes in a var, would prevent the errors. But obviously I was wrong:

var arrFrames = document.getElementsByTagName("iframe");

This didn’t help. Any suggestions how I can prevent the wrong index Issue? Or am I completely wrong about where my problem lies?
Help is much appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:41:00+00:00Added an answer on May 25, 2026 at 4:41 pm

    You can put a try-catch around the if(). That way the loop should always run without an error.

    var calculatedwidth = 0;
    var calculatedheight = 0;
    
    var searchbody = $(IframeDocument).closest('body');
    var arrFrames = document.getElementsByTagName("iframe");
    LabelA1:
    for(i = 0; i<arrFrames.length; i++){
        //console.log(i);
        //if(arrFrames[i].id != 'PeopleDetailsIframe'){
    
            try {
                if($(arrFrames[i].contentWindow.document.body).is(searchbody)){
                // This line is where my the error occures normaly
                       calculatedwidth = $(arrFrames[i]).offset().left;
                       calculatedheight = $(arrFrames[i]).offset().top;
                       break LabelA1;
                }
                else{
                      //console.log("Forum Iframe not found");
                    }
            } catch() {
                // the IFrame has security issue => avoid it
            }
         }  
    }  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small JavaScript validation script that validates inputs based on Regex. I
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
I have been unable to fix a problem with Java Unicode and encoding. The
Let's say I'm outputting a post title and in our database, it's Hello Y&#8217;all
I am currently running into a problem where an element is coming back from
I am reading a book about Javascript and jQuery and using one of the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.