简体   繁体   English

在父框架和子框架之间共享javascript包含文件

[英]Share javascript include files between parent and child frames

Its possible to share a JavaScript file between a parent and a child frame? 是否可以在父框架和子框架之间共享JavaScript文件? My idea is to prevent reloading of the same JavaScript files on each frame. 我的想法是防止在每个框架上重新加载相同的JavaScript文件。 For example, if i have jquery.js file on the parent, on the child frame that script can be inherited from the parent. 例如,如果我在父级上有jquery.js文件,则在子级框架上可以从父级继承该脚本。

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 谢谢

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). (通常,浏览器将对其进行缓存,因此您不会遇到性能问题)。

You can access the window property of a parentframe by calling parent. 您可以通过调用父级来访问父级框架的window属性。 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. 我还不能重新检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM