[Javascript] writing to iframe

Cutter java.script at seacrets.com
Fri Apr 1 19:01:40 CST 2005


John,

Unfortunately, IE is pretty far from standards compliant. Makes it 
difficult when most users (not us codemonkey types) use IE. You can 
probably find better information on how to deal with this in the W3C 
documentation of the DOM IFrame Object:

http://www.w3schools.com/htmldom/dom_obj_iframe.asp

You will find a specific example of exactly what you are trying to do 
there under the heading "Change the source of frames". I just tried this 
in Firefox and IE and it worked fine, you can view the source of the 
page for better understanding.

I used to almost exclusively code for IE. Since seeing "Mozilla" creep 
higher and higher in my various site logs over the past two years I've 
started to write cross compatible code. I've found (anybody can pipe in 
with a different opinion) that it is easier to write for Firefox, or 
other W3C standards compliant browser, first and then write the 
adjustments/hacks to deal with M$ being behind the eight ball.

My $.02. Hope the link helps,

Cutter

John Huebner wrote:

> 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.
>>
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript




More information about the Javascript mailing list