Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    May 2006
    Posts
    29
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Arrow Javascript DOM Iframe Onload

    i have successfully dynamically created an iframe object using only javascript. i couldn't get createElement() to work so i ended up just using innerHTML+= and then the actual html code. all in all, it works.

    Code:
    var iframehtml = '<iframe src="http://google.com"></iframe>';
    document.getElementById('iframeholder').innerHTML=iframehtml;
    now what i want to do is add a onload listener. once the iframe has successfully loaded the url, do something.

    how would i go about doing that?

  • #2
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Not sure what you did wrong trying to create the iframe using dom. This code does it just fine. It also has an onload set to the iframe
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>Untitled Document</title>
    <script type="text/javascript">
    window.onload = function()
    {
    	var createIframe = document.createElement('iframe');
    	createIframe.setAttribute('src','http://www.google.com');
    	createIframe.onload = function()
    	{
    		alert('hello');
    	}
    	document.getElementById('iframeholder').appendChild(createIframe);
    }
    </script>
    </head>
    
    <body>
    <div id="iframeholder"></div>
    </body>
    </html>
    ||||If you are getting paid to do a job, don't ask for help on it!||||


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •