動的にjs、cssなどのファイルをロードしてiframeにまたがって実現します。


1、動的にjsをロードし、cssファイル(元のjsとjqueryで)iframe構造:frame 0(父)frame 2(子)frame 3(子)frame 3(子)frame 2でイベントをトリガし、動的にframe 3にjs、cssファイルとdom元素をロードします。*同じレベルの間で呼び出すことができます。同じレベルのparent.parentFramをサブ-親-子で呼び出すことができます。1.jqueryのapped()
 
, ( jquery)

var oBody = document.getElementById("frame3_id").contentWindow.$("body");

var str = "<div>...</div>"
var scriptTag = document.getElementById("frame3_id").contentWindow.document.getElementById("pop");
if(!scriptTag){
oBody.append(str);
}

var oScript= document.createElement("script");
oScript.id = "oScript1";
oScript.type = "text/javascript";
oScript.src="/test.js";
var oTag1 = document.getElementById("frame3_id").contentWindow.document.getElementById("oScript1");
if(!oTag1){
oBody.append(oScript);
}

document.getElementById("frame3_id").contentWindow.test(); // frame3_id test()
************************************************上記の例:a.jqueryを導入する必要があります。2.jsのapendChild()は速度が遅く、非同期(jsがロード済みかどうかを判断する必要がある)列子2:
 
var str = "<div>...</div>"
var popDiv=document.createElement('div');
popDiv.style.xx = xxx;
popDiv.id = "pop";
popDiv.innerHTML = str;
var oBody = document.getElementById("frame3_id").contentWindow.document.getElementsByTagName("body")[0];
var oHead = document.getElementById("frame3_id").contentWindow.document.getElementsByTagName("head");

if(oHead && oHead.length){
oHead = oHead[0];
}else{
oHead = oBody;
}

var elemDivTag = document.getElementById("frame3_id").contentWindow.document.getElementById("pop");
if(!elemDivTag){
oBody.appendChild(popDiv)
}

var oScript= document.createElement("script"); (css )
oScript.id = "oScript1";
oScript.type = "text/javascript";
oScript.src="/test.js";
var scriptTag = document.getElementById("main").contentWindow.document.getElementById("oScript1");
if(!scriptTag){
oHead.appendChild(oScript);
}
oScript.onload = oScript.onreadystatechange = function(){
if ((!this.readyState) || this.readyState == "complete" || this.readyState == "loaded" ){
document.getElementById("main").contentWindow.test(); // test() js
}else{
console.info("can not load the oScript2.js file");
}
}