跨框架脚本重用

发布于 2024-10-03 09:49:21 字数 455 浏览 0 评论 0原文

我有一个在 HTA(MSFT HTML 应用程序)中运行的应用程序,它在整个框架中一遍又一遍地使用相同的脚本文件;由于这个值在某些地方达到了 9,并且应用程序是在各种服务器中设置的,并且缓存设置为立即过期,所以我试图在这个泥球中创造出某种性能。

是否有一种“好的”方法可以在顶部框架中加载主脚本文件,然后在框架内执行它,即

--- 顶部窗口 ----

var MainScript = function(){  return (function(){ all current functions etc here })(); };

--- 子框架 ----

var FrameScript = top.MainScript;
FrameScript();

这将如何受到窗口的影响范围(它会保留顶部窗口范围还是在框架窗口范围内)

I have an application running in a HTA (MSFT HTML Application) that uses the same script file over and over again throughout frames; as this hits 9 in places and as the application is setup within various servers with caching set to immediate expire I'm trying to carve out some sort of performance in this ball of mud.

Is there a 'good' way to load the main script file in the top frame then excuting it within the frames i.e.

--- TOP WINDOW ----

var MainScript = function(){  return (function(){ all current functions etc here })(); };

--- SUB Frames ----

var FrameScript = top.MainScript;
FrameScript();

And how would this be affected by window scope (would it keep the top window scope or be in scope of the frame-window)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半衬遮猫 2024-10-10 09:49:21

最简单的方法似乎是给子框架一个 ID,然后用主框架中加载的脚本动态填充它(使用 eval 使 js 运行);

|> 父框架(又名顶部框架)

<script>top.windows = [];</script>
<script id="MyScript">
    var test = function(){ top.windows.push(window); }
</script>

|>>> 子框架
在 IFrame 中加载 SubSubFrame

|>> SubSubFrame

<script id="SF1">
document.getElementById("SF1").innerHTML = eval(top.window.document.getElementById("MyScript").innerHTML);
test();
</script>

这适用于受信任域内深度可达 8 帧的深度(在 .hta 中,您为此在框架上设置 application=true),

我使用了 top.windows[],因此我可以检查范围。 (将其输入到 firebug 中的 console.log(top.windows) 中)

令人作呕且深奥; Google 做了类似延迟 JS 加载/执行的事情。

The simplest method appears to be to give the subframe an ID then to dynamically populate it with the script loaded in the master frame (using eval to make the js run);

i.e.

|> Parent (aka TOP Frame)

<script>top.windows = [];</script>
<script id="MyScript">
    var test = function(){ top.windows.push(window); }
</script>

|>> SubFrame
Loads SubSubFrame in an IFrame

|>>> SubSubFrame

<script id="SF1">
document.getElementById("SF1").innerHTML = eval(top.window.document.getElementById("MyScript").innerHTML);
test();
</script>

This Works upto and beyond 8 frames deep within a trusted domain (in a .hta you set application=true on the frames for this)

I used top.windows[] so I could check the scope. (type it into console.log(top.windows) in firebug)

Nausiating and deep; Google do something similar to delay JS loading/execution.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文