[Javascript] Poorly documented facet of cross-frame execution

Peter-Paul Koch gassinaumasis at hotmail.com
Tue Apr 8 01:45:39 CDT 2003


exists in a <script
>language='JavaScript'>...</script> block in the header of mycode1.html, the 
>following will NOT work:
>
>   parent.document.frames["frameA"].document.foobar();
>
>The reason is that the 'document' object in frameA's code module doesn't 
>REALLY begin until it hits the <body> tag.  The correct procedure is 
>therefore
>
>   parent.document.frames["frameA"].foobar();

As far as I understand it has little to do with the BODY tag, but everything 
with the fact that the defined functions are properties/objects of the 
global object in the other frame. The global object is window, or self, and 
in the case of other frames parent.frames['name'] (not that here, too, I 
don't use 'document', though I'm less sure why not).

As far as I know the HEAD/BODY thing has little to do with the 
window/document difference.

>On a related subject, the erroneous assumption that onLoad correctly 
> >denotes the completion of the entire screen build can be easily tested 
> >by simply putting an onLoad='alert("done loading...")' declaration at 
> >the end of the <body> tag.  Unless you're
>dealing with some incredibly wimpy window, the alert will come up >ALWAYS 
>with part of the screen still undefined.  All those objects >which have yet 
>to be painted (which may NOT be merely jpegs and the >like, as 
>certain-people-who-will-remain-nameless
>suggested earlier) cannot be referenced by any code within the routine 
> >pointed to by the onLoad event.  In short, onLoad is broken.

No, it isn't. onLoad fires when all arrays like document.forms and 
document.images have been initialized and are accessible. Though indeed some 
images may not display yet, all elements inside the document are accessible 
onLoad, and that's the point of the event handler.

--------------------------------------------------
ppk, freelance web developer
Interaction, copywriting, JavaScript, integration
http://www.xs4all.nl/~ppk/
Column "Keep it Simple": http://www.digital-web.com/columns/keepitsimple/
--------------------------------------------------


_________________________________________________________________
Help STOP SPAM with the new MSN 8 and get 2 months FREE*  
http://join.msn.com/?page=features/junkmail



More information about the Javascript mailing list