...

View Full Version : Writing to an iframe in a framepage in Firefox



Joat
05-30-2009, 12:33 AM
I have seen plenty of online sources tell of how to write to an iframe, that it is a property of "window". But the problem is, the iframe in question is in a frame itself. How do I refer to such an iframe?

Kor
05-30-2009, 09:46 AM
I have seen plenty of online sources tell of how to write to an iframe, that it is a property of "window". But the problem is, the iframe in question is in a frame itself. How do I refer to such an iframe?
Refer the iframe from where? From the parent frame? From the general parent? From another frame/iframe? Describe the structure of your page, please.

Joat
05-31-2009, 12:36 AM
A script in the top-left frame writing content to an iframe in the same frame. The script may be called from another frame, but the script itself is in the same frame.

Kor
05-31-2009, 06:15 AM
So the code is in the same frame with the iframe. Now give your iframe an id, say id="myiframe". Now, the iframe, as a Global Object (window), is to be referred as:


var ifr=document.getElementById('myiframe').contentWindow

Well, there were some problems around contentWindow method (which is not quite DOM standard, even it is recognized now by all the modern browsers). If you feel the need to be pedantic, you may access the document of the iframe like:


var x=document.getElementById('myiframe');
var ifr_document;
if(x.contentWindow){
ifr_document=x.contentWindow.document;
}
else{
ifr_document=x.contentDocument;
}


----

IMPORTANT note. Javascript reference for frames or iframes works only if both (the parent document and the iframe/frame document) belong to the same domain. Cross-domain javascript relationship is not possible, due to obvious security reasons.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum