[Javascript] writing to iframe
Andrew Clover
and-babble at doxdesk.com
Tue Apr 5 05:31:35 CDT 2005
John Huebner <jhuebner08 at student.mvcc.edu> 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();
Yes, that should work. 'window' is in scope as it is, so the 'window.'
prefix is only technically necessary if you plan to have a local
variable overriding the name 'frames'. You can include it anyway, for
safety or to make the code clearer - your call.
> However, I don't understand why it the script needs to write to the file
> on the server.
It doesn't write to the server as such. Pointing the src to a document
on the same server means you get access to the frame's 'document'
property. Pointing it to a different server means the script is
disallowed access.
> The iframe starts out empty, no src value at all.
This will indeed work in many browsers, but in my experience fails under
Opera (up to version 7). If cross-browser compatibility is a concern,
including a src pointing to the current server is a good idea.
> On the other hand, netscape does not.
Works for me. Check your document validates and/or try doing the writing
after the document is finished (eg. onload)... in my experience under
Mozilla-based browsers the window.frames array may be 'not ready' at
<script>-block-running-time if you have omitted key elements such as <body>.
--
Andrew Clover
mailto:and at doxdesk.com
http://www.doxdesk.com/
More information about the Javascript
mailing list