1. 동적으로 JS 및 CSS 파일 (기본 JS 및 JQuery 사용)을로드합니다.
iframe 구조 :
프레임 0 (아버지)
frame2 (sub)
frame3 (sub)
Frame2의 트리거 이벤트, 동적으로 JS, CSS 파일 및 DOM 요소를 Frame3에로드 하시겠습니까?
*동일한 수준 사이에서 호출 할 수 있으며 아동 부모와 동일한 수준을 호출 할 수 있습니다.
parent.parentfram ( "이 방법은 다른 아동 농장이라고 부릅니다");
1. jquery 's append ()
코드 사본은 다음과 같습니다.
빠른 속도, 동기식 (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 ( "스크립트");
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);
}
geteLementById ( "frame3_id"). contentwindow.test ();
****************************************
위의 예 : a. jQuery를 소개해야합니다.
****************************************
2.JS AppendChild ()
느린 속도, 비동기식 (JS가로드되었는지 확인해야 함)
Lesson 2:
코드 사본은 다음과 같습니다.
var str = "<div> ... </div>"
var popdiv = document.createElement ( 'div');
popdiv.style.xx = xxx;
popdiv.id = "팝";
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];
}또 다른{
ohead = Obody;
}
var elemdivtag = document.getElementById ( "frame3_id"). contentwindow.document.getElementById ( "pop");
if (! elemdivtag) {
Obody.appendChild (Popdiv)
}
var oscript = createelement ( "스크립트");
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 ();
}또 다른{
console.info ( "oscript2.js 파일을로드 할 수 없음");
}
}