This article mainly introduces the dynamic loading of JS, CSS and other documents across the implementation of the method of IFRAME, the need for friends can refer to the following
1. Dynamically loading Js,css files (with native JS and jquery) IFRAME structure: FRAME0 (parent) Frame2 (sub) Frame3 (sub) Triggering events in Frame2, dynamically loading JS, CSS files, and DOM elements into Frame3? * Siblings can be called between siblings by calling the sibling Parent.parentfram ("This method calls other child Farme"); 1.jquery append () Code as follows: Fast, sync (need to introduce 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"; nbsp 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 (); Call the test () method in frame3_id *********************************** The above example: a. Need to introduce jquery; ********** 2.js appendchild () slow, asynchronous (need to determine whether JS is loaded) 2: The code is as follows: 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 similar) 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 () method in the JS file introduced }else{ Console.info ("Can not load the Oscript2.js file"); } }