1

Its possible to share a JavaScript file between a parent and a child frame? My idea is to prevent reloading of the same JavaScript files on each frame. For example, if i have jquery.js file on the parent, on the child frame that script can be inherited from the parent.

frame souce:

<frameset rows="78px,*" framespacing="0" frameborder="0" border="0">
    <frame src="indexFrame.html" name="status" id="status"/><!-- noresize="noresize" scrolling="no"-->
    <frame src="DeviceTreeMenu.html" name="desktop" id="TreeMenu"/>
    <noframes>
        <body>
            <p>This page requires frame support and apparently this Web browser doesn't support this feature. Please check the Browser configuration, switch to another browser or try the <a href="menu.html">menu page</a> as a resort.</p>
        </body>
    </noframes>
</frameset>

Thank you

lmpc
  • 11
  • 3
  • can you add some example HTML to show us your "frame" setup (is frame iframe or actual frames (from the 80's)) ? – Manse May 21 '12 at 11:10
  • if you care about bandwith, consider the fact browsers already manage this with their caches. I've even read rumours that chrome caches a compiled version of scripts. Find it: http://stackoverflow.com/questions/1096907/do-browsers-parse-javascript-on-every-page-load – BiAiB May 21 '12 at 13:14
  • yes i care about bandwith, because im using gprs connection. Talking about cache, it seems that firefox isnt caching my request like chrome does, i dont know why and because of that, im trying to reduce javascripts includes. – lmpc May 21 '12 at 14:41

2 Answers2

0

You have to include it in both. Frames are similar to different windows or tabs. (Usually the browser will cache it, so you will not have a performance issue).

richardtz
  • 4,945
  • 2
  • 23
  • 38
0

You can access the window property of a parentframe by calling parent. In that way you can import properties from the parent.

parent.document.body.appendChild(parent.document.createTextNode("Foobar"));
var $ = parent.$ // e.g. jquery instance of parentframe 

Note that depending on the browser implementation, that the context of the function calls may or may not be changed to the parentwindow. I couldn't recheck that yet.

Gottox
  • 640
  • 6
  • 14