views:

319

answers:

2

If I have a document with a frameset and some javascript defined in a head tag, i.e something like this:

<html>
 <head>
  <script>
     function foo() {}
  </script>   
 </head>
 <frameset>
    <frame src="A.html">
 </frameset>     
</html>

I am already assuming that the frame (A.html) fires its onLoad event handler before that of its parent. I'm almost positive that is a safe assumption. However, is it safe to assume that the script context of A.html can safely access all of the script code defined in the head of the parent window?

What assumptions can I make?

+1  A: 

According to this page, you can safely access the script in the parent, which is the object referring to a frame's parent frameset document.

From a little local test, the parent's onload event doesn't seem to fire, but the its script tag all seems to have been processed before the child frames are loaded.

Framesets are frowned on these days, so be sure that it's the right approach.

Phil H
+1  A: 

The frame script will be able to access its parent JS space via the parent reference. (But only if the two documents are on the same host - which they are in your stripped-down example).

I wouldn't rely on parent's onLoad firing after A.html's, though as Phil mentioned, the script will process first - this is because inline script evaluation is a blocking operation.

levik