Code in place, now need a onLoad function?

Discussion in 'JavaScript' started by ehime, Oct 1, 2008.

  1. #1
    I patched together code to grab a file from a url (stripped html) and
    inject it into an IFrame for swappable layering. I still need to put together
    an onload default page to snatch, but it has me scratching my head.

    I tried <body onload="loadOuter('main.html')> but it morphed my layout
    and just plain didn't work in general. Any suggestions appreciated!

    swaplayer.js
    
    
    var srcFrame;
    
    //External content into a layer
    function loadOuter(doc) {
     srcFrame = document.getElementById("hiddenContent");
     srcFrame.src = doc;
    
     // workaround for missing onLoad event in IFRAME for NN6
     if (!srcFrame.onload) {
      setTimeout("transferHTML()", 500)
     }
    }
    
    function transferHTML(){
     srcContent='';
     if (srcFrame.contentDocument){
      srcContent=srcFrame.contentDocument.getElementsByTagName("BODY")[0].innerHTML;
     }
     else if (srcFrame.contentWindow){
      srcContent=srcFrame.contentWindow.document.body.innerHTML;
     }
     document.getElementById("outerDisplay").innerHTML = srcContent
    }
    
    
    var DocAry=new Array('');
    
    function SelectList(v){
     if (v>0){
      loadOuter(DocAry[v-1]);
     }
    }
    
    Code (markup):
    And HTML mechanism and injection site
    
    <a href="#" onClick="loadOuter('main.html')">home.</a>
    .....
    <iframe id="hiddenContent" width="200" height="200" style="position:absolute;visibility:hidden;width:auto;height:auto;" ></iframe>
    
    Code (markup):

     
    ehime, Oct 1, 2008 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    erm, you may want a framework that can do a proper onload / dom ready for you (hard to say what is causing the error without looking at the live example with firebug :D )

    in mootools, you'd have something like
    window.addEvent("domready", function() {
       // we know the page is safe and DOM is available to modify, all browsers.
       loadOuter('main.html'); // ...
    });
    Code (markup):
    in jquery it's
    $(document).ready(function(){
      loadOuter('main.html'); // ...
    });
    Code (markup):
    etc etc. basically, the frameworks are already doing all the hard work for you :)
     
    dimitar christoff, Oct 2, 2008 IP
  3. ehime

    ehime Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I'm loading framework with JQuery-1.2.3.pack.js, I
    ended up inserting your jquery code and it worked
    GREAT. Thanks Dimitri, you got me one huge
    step closer to going live.
     
    ehime, Oct 3, 2008 IP