problem with : document.createElement("iframe") and onload

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andy Gritsan
    New Member
    • Jul 2011
    • 3

    #1

    problem with : document.createElement("iframe") and onload

    1.
    Code:
    newFrame = document.createElement("iframe");       
    newFrame.id='aa1';
    newFrame.onload = aa(this.id);
    document.getElementsByTagName('body')[0].appendChild(newFrame);
    function aa(id){alert(id);}
    output: undefined
    2.
    Code:
    document.write("<br><iframe id = 'aa1' onload = 'aa(this.id)'></iframe>");
    function aa(id){alert(id);}
    output: aa1
    Why in 1 output undefined?
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    What is this object? where does it come from? this object is invalid here. resolve it first

    Comment

    • ivansyah
      New Member
      • Aug 2011
      • 3

      #3
      onload is Body ELement function....
      I think what u need is
      Code:
      newFrame = document.createElement("iframe");       
      newFrame.id = 'aa1';
      document.body.appendChild(newFrame) ;
      document.body.onload = aa(newFrame.id) ;
      function aa(id){alert(id);}

      Comment

      • Andy Gritsan
        New Member
        • Jul 2011
        • 3

        #4
        resolved, thank you!

        Comment

        Working...