Dynamically loaded JS, CSS and other files across the IFRAME implementation

Source: Internet
Author: User

  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"); } }     
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.