SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Zealot diskhub's Avatar
    Join Date
    Jun 2004
    Location
    singapore
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    window.parent.content.document doesn't work in IE?

    Hi All,
    I have a page(A) with an iframe which src is link to another page(B).

    I wrote a javascript in page B to do a getElementById on pageA, using window.parent.content.document.getElementById()

    This works perfectly for firefox and not ie...
    i am using ie7. Can anyone guide me how to solve this problem?

    Thanks
    I LOVE PHP!!!

  2. #2
    SitePoint Wizard chris_fuel's Avatar
    Join Date
    May 2006
    Location
    Ventura, CA
    Posts
    2,750
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IE uses contentWindow. Here's a simple function to get an IFrame's document for such calls:

    Code:
    function getIframeDocument(element)
    {
      var doc = element.contentDocument;
      if (doc == undefined || doc == null)
      {
        doc = element.contentWindow.document;
      } 
      return doc;
    }

  3. #3
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Nelson BC
    Posts
    2,310
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I would've thought that:

    window.parent.document.getElementById()

    would work.

  4. #4
    SitePoint Zealot diskhub's Avatar
    Join Date
    Jun 2004
    Location
    singapore
    Posts
    161
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi all,
    i think
    Code:
    function getIframeDocument(element)
    {
      var doc = element.contentDocument;
      if (doc == undefined || doc == null)
      {
        doc = element.contentWindow.document;
      } 
      return doc;
    }
    but I need a script to be coming from the iframe to know get an element from the parent. I think that script you wrote is for the parent window right?

    and what is element in the function by the way?
    I LOVE PHP!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •