문제

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)

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top