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 1036615
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T14:43:58+00:00 2026-05-16T14:43:58+00:00

Say I have a reference to a document object, which is contained inside an

  • 0

Say I have a reference to a document object, which is contained inside an IFRAME. How do I get a reference to the container IFRAME? .parentNode and .ownerDocument both return null.

Please note that no context information is available (e.g. solutions like ‘window.xxx’ will not work) – all that’s available is a reference to the document object.

Thanks

  • 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-16T14:43:59+00:00Added an answer on May 16, 2026 at 2:43 pm

    A document is not directly connected to its parent document. You do need a reference to window in order to pick up the parent.

    The DOM Level 2 Views property document.defaultView will give you the window in most modern web browsers, but in IE you have to use the non-standard document.parentWindow instead. (Some older or more obscure browsers don’t implement either of these properties, in which case you’re stuck.)

    That’ll give you the window of the parent document. If you want to get the <iframe> that holds your document, you’ll have to iterate through all the iframes on the page and check whether the contained document is yourself.

    Again, the method to get from an iframe element back to the child is gratuitously different in IE (iframe.contentWindow giving you the window) vs the DOM standard and everyone else (iframe.contentDocument giving you the document).

    So, something like:

    function getFrameForDocument(document) {
        var w= document.defaultView || document.parentWindow;
        var frames= w.parent.document.getElementsByTagName('iframe');
        for (var i= frames.length; i-->0;) {
            var frame= frames[i];
            try {
                var d= frame.contentDocument || frame.contentWindow.document;
                if (d===document)
                    return frame;
            } catch(e) {}
        }
    }
    

    (The try... is to avoid crashing the loop out when a document access fails due to another iframe being on a different domain, causing a Same Origin Policy error.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Say, i have a function which returns a reference and i want to make
Lets say that I have a element reference obtained ala... var x=document.getElementById(ID123); Now I
Say I have some 10 categories that I need to reference in a web
For reference, the code is for the motorola 68008. Say I have code such
let's say you have a url like this entered in modx Evo www.zipit.com.org/reference/toamovie/ if
In JavaScript, let's say we have a main page ( main.html ) which contains
Using Mongoid, let's say I have the following classes: class Map include Mongoid::Document embeds_many
UIImage API Reference Document:- initWithContentsOfFile: Initializes and returns the image object with the contents
let's say that i have something like this: <head><script src=script1.js ...></script></head> <body><div id=div1></div></body> which
Let's say I have two simple models project t.string :title vote t.references :project t.integer

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.