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

IE uses contentWindow. Here’s a simple function to get an IFrame’s document for such calls:


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

I would’ve thought that:

window.parent.document.getElementById()

would work.

Hi all,
i think

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?