[thelist] [javascript] referencing an iframe from a child window

Paul Bennett paul at teltest.com
Thu Oct 2 18:55:55 CDT 2003


Tom Dell'Aringa wrote:

>--- Paul Bennett <paul at teltest.com> wrote:
>  
>
>>'Volters, I want to reference an iframe in a parent window from a 
>>function in a child window.
>>
>>I can reference the DOM of the parent window fine using things like
>>window.parent.document .. but from what I can see an Iframe is
>>treated as a seperate document to the document it is contained in.
>>I can reference it from the parent document (by using it's id) but
>>don't seem to be able to do the same from the child window.
>>Can anyone give me any pointers on how to reference it?
>>    
>>
>
>Paul,
>
>Its a bit hard to glean the structure of what you have without a
>clearer explanation - but an iFrame is referenced just like any other
>frame, so you can use the frames[] array.
>
ok, I have a content management system using the MSIE 5.5+ content 
editing functions. All is working fine and dandy there
The editable content is placed into an iframe (id="iBody") and all 
execCommand calls are directed to the content in the iFrame

I can access the iFrame content from within the page by using calls like:
iBody.document.execCommand('bold', false, null);

Now I want to open a window, list images from a directory and make it so 
when you click them they are inserted into the iFrame ("iBody")

so my function to insert the image is:

function doImageInsert (ImgName)
            {
             // get the iFrame object
            i_Target = window.parent.document.getElementById['iBody'];
            // focus it
            i_Target.focus();
            // execute the InsertImage command into the iFrame
            i_Target.document.execCommand ( \'InsertImage\', false, 
ImgName);
            // close the child window
            self.window.close ();
            }

But the script dies at the iFrame assignment into the i_Target variable 
- claiming it is 'NULL or not an object'

Any more ideas on how I can get the ifram from the child window?


-- 
 ------------------------------
	Paul Bennett						
	Internet Developer				
	Teltest Electronic Design		
 ------------------------------			
Email: paul at teltest.com				
Phone: 64 4 237 4557					
Web: http://www.teltest.com		
Wap: http://wap.teltest.com			




More information about the thelist mailing list