[Javascript] writing to iframe

John Huebner jhuebner08 at student.mvcc.edu
Fri Apr 1 15:00:37 CST 2005


So you're saying it should be

window.frames.iframe_name.document.open();
window.frames.iframe_name.document.write("content to write");
window.frames.iframe_name.document.close();

However, I don't understand why it the script needs to write to the file 
on the server. I am trying to write to the iframe within the current 
document. The iframe starts out empty, no src value at all.

As I've said, It works in IE. IE seems to except it almost no matter how 
I write it. On the other hand, netscape does not. As I said. I can get 
netscape to write to the iframe the first time through but after that it 
fails.

I'm afraid you've lost me on with some of what you said.

I will try the above. Somehow I'm afraid that it is a problem with the 
Mozilla based browsers though.

If I have the above wrong please let me know,

As I said, I appreciate any input I can get on this.

Andrew Clover wrote:
> John Huebner <JHuebner08 at student.mvcc.edu> wrote:
> 
>> Iframe_name.document.open;
>> Iframe_name.document.clear;
>> Iframe_name.documentl.write("content to be written");
>> Iframe_name.document.close;
> 
> 
> open, clear and close are methods too, so if you want to call them 
> (rather than just refer to them) you have to say open(), clear() and 
> close(). You shouldn't need document.clear() anyway.
> 
> Avoid writing just 'Iframe_name' - this requires that the browser copies 
> references to named items as properties of the 'window' object (which 
> acts like a global scope for a web page script). Most browsers *will* do 
> this - not least because IE and Moz make 'window.frames' a synonym for 
> 'window' - but it's best not to rely on it.
> 
> You should also ensure that the iframe src points to a document on the 
> same hostname, so that you're allowed to access its 'document' property.
> 
>> I've even tried to call the iframe using
> 
> 
>> window.frames("Iframe_name").document
> 
> 
> Nearly.
> 
> window.frames is supposed to be accessed like an Array (in some browsers 
> it might actually be one), so use square instead of round brackets to 
> access things from it.
> 
> By the way in JavaScript, property and member access are the same thing, 
> so:
> 
>   window.frames['Iframe_name'].document
> 
> is the same as saying:
> 
>   window.frames.Iframe_name.document
> 
> You only need the brackets if the name is not a valid identifier (ie. it 
> has funny characters in) or if you want to use a variable to hold the 
> property name you're going to access.
> 




More information about the Javascript mailing list