Re: Accessing an IFrame's properties
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Accessing an IFrame's properties

From: Lasse Reichstein Nielsen <lrn@hotpop.com>
Date: Sun Apr 30 2006 - 23:44:11 CEST

Declan Naughton <piratepenguin@gmail.com> writes:

> Seeing as window.frames isn't a part of any w3c standard, surely there
> must be another (standards-compliant) way to access the properties of a
> document included using the iframe or object elements (preferably
> object)... right?

Yes.

---
 var iframeElem = document.getElementById("myIframeId");
 var iframeDoc = iframeElem.contentDocument;
 iframeDoc.body.style.backgroundColor="red"; // i'm in!
---
Does it work in IE? Ofcourse not.
In IE, iframe elements does not have a "contentDocument" property.
They do have a "contentWindow", so you can do:
---
 var iframeDoc = iframeElem.contentDocument || 
     (iframeElem.contentWindow && iframeElem.contentWindow.document);
---
 
Good luck.
/L
-- 
Lasse Reichstein Nielsen  -  lrn@hotpop.com
 DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
  'Faith without judgement merely degrades the spirit divine.'
Received on Mon May 1 05:28:24 2006